首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >NSAppleScript自动打开iTunes

NSAppleScript自动打开iTunes
EN

Stack Overflow用户
提问于 2012-07-14 21:21:12
回答 1查看 137关注 0票数 0

这不应该在iTunes关闭时获得歌曲名称,因为iTunes必须打开它才能检查并返回false。

请帮帮忙。

代码语言:javascript
复制
//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]];
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-07-14 22:25:05

你可能会有更好的运气,比如:

代码语言:javascript
复制
if ([[NSRunningApplication runningApplicationsWithBundleIdentifier:@"com.apple.iTunes"] count] != 0) {
    // run your script
} else {
    // itunes isn't running
}
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/11484102

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档