0

これは、iTunes が閉じているときに曲名を取得するべきではありません。これは、iTunes を開いて確認し、false を返す必要があるためです。

助けてください。

//run applescript
NSAppleScript *script = [[NSAppleScript alloc] initWithSource:@"try\n tell application \"System Events\" to set checkIfItunesIsRunning to (name of processes) contains \"iTunes\"\n if checkIfItunesIsRunning is equal to true then\n tell application \"iTunes\" to get name of current track\n else\n return \"No Song\"\n end if\n on error errmsg number errNum\n return \"No Song\"\n end try"];

NSAppleEventDescriptor *theResult = [script executeAndReturnError:nil];
//Set MenuItem
    [song setTitle:[theResult stringValue]];
4

1 に答える 1

2

次のようなもので運が良いかもしれません:

if ([[NSRunningApplication runningApplicationsWithBundleIdentifier:@"com.apple.iTunes"] count] != 0) {
    // run your script
} else {
    // itunes isn't running
}
于 2012-07-14T14:25:04.953 に答える