pyobj 访问 iTunes 应用程序
假设我设法在 Applescript 编辑器中为 iTunes 打开字典:
如何使用 Python 和 pyobjc 访问“搜索”命令?
来获取 iTunes 应用程序,
我知道我可以使用iTunes = SBApplication.applicationWithBundleIdentifier_("com.apple.iTunes")
但在我对其执行 dir
后,我在返回的字典中看不到搜索命令。请帮忙!
Let's say I managed to get the dictionary opened for iTunes in the Applescript editor:
How would I access the "search" commands using Python with pyobjc?
I know I get can hold of the iTunes application using:
iTunes = SBApplication.applicationWithBundleIdentifier_("com.apple.iTunes")
but after I do a dir
on it, I don't see the search command in the returned dictionary. Help please!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用 appscript 而不是 Scripting Bridge。有适用于 Python、Ruby 和 Objective-C 的版本。与 Scripting Bridge 不同,appscript 旨在与 Apple Events 配合使用,而不是让它假装成不是的东西;它也更加灵活并且错误更少。作为奖励,您不必通过 PyObjC。
appscript 文档很好,值得一读。您可以安装 ASTranslate ,它将 AppleScript 脚本转换为上述任何语言的 appscript 代码。当我做一些棘手的事情时,我经常在(Apple)脚本编辑器中编写它,然后使用 ASTranslate 转换为 Python。还有 ASDictionary,它生成针对 appscript 语言格式化的 HTML 格式版本的词典;我不经常使用它,因为我发现尝试脚本编辑器更容易。 (但是,如果您没有太多使用 AppleScript 的经验,也许它会是更好的选择。)
有关使用 Python appscript 控制 iTunes 的一些示例,您可以参阅 一些 脚本 我写的。
Use appscript instead of Scripting Bridge. There are versions available for Python, Ruby and Objective-C. Unlike Scripting Bridge, appscript is designed to work with Apple Events rather than make it pretend to be something it isn't; it's also quite a bit more flexible and less buggy. As a bonus, you don't have to go through PyObjC.
The appscript documentation is good and worth reading. You can install ASTranslate which will convert an AppleScript script into appscript code for any of the above languages. When I'm doing something tricky, I often write it in (Apple)Script Editor, then convert into Python with ASTranslate. There's also ASDictionary, which produces HTML-formatted versions of dictionaries formatted for appscript languages; I don't use it much since I find experimenting with Script Editor more accessible. (However, if you don't have much experience with AppleScript, maybe it'd be a better choice.)
For some examples of controlling iTunes with Python appscript, you can see some scripts I wrote.