差分
ナビゲーションに移動
検索に移動
==実装例1==
[[MonoMac]]には[[AppleScript]]を[[コンパイル]]したり実行したりするNSAppleScriptクラスが存在しないようだ。応急処置的ではあるが[[コマンドライン]]から[[AppleScript]]を実行するosascriptコマンドを使えば一応は問題ないようだ。
<source lang="csharp">
public override void AwakeFromNib()
{
base.AwakeFromNib();
// 再生ボタンを押したときの処理
playButton.Activated += (object sender, EventArgs e) => {
using (var p = new System.Diagnostics.Process())
{
// iTunesで再生する
p.StartInfo.FileName = "osascript";
p.StartInfo.Arguments = "-e 'tell application \"iTunes\" to play'";
//出力を読み取れるようにする
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.RedirectStandardInput = false;
//実行
p.Start();
//出力を読み取る
var results = p.StandardOutput.ReadToEnd();
Console.WriteLine(results);
//プロセス終了まで待機する
p.WaitForExit();
}
};
}
</source>
定型文的に決まったAppleScriptであればBundle Resourceにテキストファイルとして用意しておいて、osascriptコマンドにファイル引数を渡すのもありかもしれない。
==関連項目==
==参考文献==
{{reflist}}
{{stub}}
[[category:MonoMac]]
[[MonoMac]]には[[AppleScript]]を[[コンパイル]]したり実行したりするNSAppleScriptクラスが存在しないようだ。応急処置的ではあるが[[コマンドライン]]から[[AppleScript]]を実行するosascriptコマンドを使えば一応は問題ないようだ。
<source lang="csharp">
public override void AwakeFromNib()
{
base.AwakeFromNib();
// 再生ボタンを押したときの処理
playButton.Activated += (object sender, EventArgs e) => {
using (var p = new System.Diagnostics.Process())
{
// iTunesで再生する
p.StartInfo.FileName = "osascript";
p.StartInfo.Arguments = "-e 'tell application \"iTunes\" to play'";
//出力を読み取れるようにする
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.RedirectStandardInput = false;
//実行
p.Start();
//出力を読み取る
var results = p.StandardOutput.ReadToEnd();
Console.WriteLine(results);
//プロセス終了まで待機する
p.WaitForExit();
}
};
}
</source>
定型文的に決まったAppleScriptであればBundle Resourceにテキストファイルとして用意しておいて、osascriptコマンドにファイル引数を渡すのもありかもしれない。
==関連項目==
==参考文献==
{{reflist}}
{{stub}}
[[category:MonoMac]]