iTunes に通知を送信して、現在の曲を教えてくれる方法はありますか。曲の変更時に通知が送信されることはわかっていますが、アプリケーションを開いたときに現在の曲を取得したいと考えています。スクリプト ブリッジの使用を避けようとしています。
2 に答える
2
残念ながら、通知を使用してこれを行うことはできません。唯一のオプションは、スクリプト ブリッジまたはその他の Apple イベント関連のメソッドです。
于 2012-04-26T01:53:27.860 に答える
1
NSAppleScriptを使用して AppleScript を実行できます。
例: 現在のトラックのタイトルとアーティストを取得するには
NSAppleScript* theScript = [[NSAppleScript alloc] initWithSource:
[NSString stringWithFormat:
@"tell application \"iTunes\" to if running then\n"
@" try\n"
@" tell current track to return name & return & artist\n"
@" end try\n"
@" return \"no track\"\n"
@"end if\n"
@"return \"iTunes is not open\"\n"]];
NSDictionary *errorDict;
NSAppleEventDescriptor *resultDescriptor = [theScript executeAndReturnError:&errorDict];
NSString *title_artist = [resultDescriptor stringValue];
// do something with title_artist
例:「リソースフォルダ」にあるAppleScriptファイルを利用する場合
NSString *scriptPath = [[NSBundle mainBundle] pathForResource:@"theScriptName" ofType:@"scpt"];
NSAppleScript *theScript = [[NSAppleScript alloc] initWithContentsOfURL: [NSURL fileURLWithPath:scriptPath] error: nil];
別の解決策: NSTaskを使用して、osascript 経由で AppleScript を実行できます。
于 2012-04-26T06:11:42.197 に答える