这不应该在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]];发布于 2012-07-14 22:25:05
你可能会有更好的运气,比如:
if ([[NSRunningApplication runningApplicationsWithBundleIdentifier:@"com.apple.iTunes"] count] != 0) {
// run your script
} else {
// itunes isn't running
}https://stackoverflow.com/questions/11484102
复制相似问题