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 回答