iTunes Apple 事件 API

发布于 2024-09-01 13:04:31 字数 454 浏览 2 评论 0原文

我想通过 Objective-C 控制 iTunes(我只是无法在我的 OS/X 10.6.3 系统上正确安装 Python appscript ...那是我的第一选择)。

据我所知,Cocoa 上的 IPC 基于 Apple Events :是否有:

  1. iTunes / Apple Events API 的在线文档?
  2. 获取 iTunes API 的自省机制?

我了解 Applescript 编辑器/开放词典功能,但我不知道如何将我看到的信息翻译为 IPC 调用。

注意:我已经尝试通过PyObjC制定解决方案,但我追求的主要功能是轨迹搜索,我无法弄清楚。

免责声明:这里是 OS/X 超级新手。

I'd like to control iTunes through Objective-C ( I just can't get Python appscript installed correctly on my OS/X 10.6.3 system ... that would have been my first choice ).

From what I gather, the IPC on Cocoa is based on Apple Events : is there either:

  1. Online documentation on iTunes / Apple Events API ?
  2. Instrospection mechanism to get to iTunes API?

I know about Applescript Editor / Open Dictionary functionality but I can't figure out how to translate the information I see into IPC calls.

Note: I have already tried working out a solution through PyObjC but the main function I am after is track searching which I can't figure out.

Disclaimer: OS/X super-newbie here.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

〃安静 2024-09-08 13:04:31

您是否考虑过使用脚本桥?它内置于操作系统中,也可与 PyObjC 配合使用。没有明显的搜索 API,因为搜索内置于 AppleScript 中 (whose 子句),映射到 Scripting Bridge 中的 NSPredicate。

>>> from Foundation import *
>>> from ScriptingBridge import *
>>> itunes = SBApplication.applicationWithBundleIdentifier_(u"com.apple.itunes")
>>> tracks = itunes.sources()[0].libraryPlaylists()[0].tracks()
<SBElementArray @0x468a630: every ITunesTrack of ITunesLibraryPlaylist 0 of ITunesSource 0 of application "iTunes" (157)>
>>> predicate = NSPredicate.predicateWithFormat_(u'artist == "Pink Floyd"')
>>> tracks.filteredArrayUsingPredicate_(predicate)
<SBElementArray @0x457b6c0: ITunesTrack whose 'cmpd'{ 'relo':'=   ', 'obj1':'obj '{ 'want':'prop', 'from':'exmn'($), 'form':'prop', 'seld':'pArt' }, 'obj2':'utxt'("Pink Floyd") } of ITunesLibraryPlaylist 0 of ITunesSource 0 of application "iTunes" (157)>

另外,如果您是 AppleScript 新手,我强烈推荐 Script Debugger 的字典浏览器

Have you considered using Scripting Bridge? It's built into the OS and also works with PyObjC. There's no distinct searching API because searching is built into AppleScript (whose clauses), which map to NSPredicate in Scripting Bridge.

>>> from Foundation import *
>>> from ScriptingBridge import *
>>> itunes = SBApplication.applicationWithBundleIdentifier_(u"com.apple.itunes")
>>> tracks = itunes.sources()[0].libraryPlaylists()[0].tracks()
<SBElementArray @0x468a630: every ITunesTrack of ITunesLibraryPlaylist 0 of ITunesSource 0 of application "iTunes" (157)>
>>> predicate = NSPredicate.predicateWithFormat_(u'artist == "Pink Floyd"')
>>> tracks.filteredArrayUsingPredicate_(predicate)
<SBElementArray @0x457b6c0: ITunesTrack whose 'cmpd'{ 'relo':'=   ', 'obj1':'obj '{ 'want':'prop', 'from':'exmn'($), 'form':'prop', 'seld':'pArt' }, 'obj2':'utxt'("Pink Floyd") } of ITunesLibraryPlaylist 0 of ITunesSource 0 of application "iTunes" (157)>

Also, if you're new to AppleScript, I highly recommend Script Debugger's dictionary explorer.

放手` 2024-09-08 13:04:31

如果您在使用 py-appscript 时遇到问题,请联系作者(即我)来解决问题。包括有关正在使用的 Python 安装、Xcode 版本以及问题是否特定于 appscript 或影响所有第三方模块或具有 C 扩展的第三方模块的信息。另外,如果您使用 python.org 框架构建而不是内置 Python,请确保安装了可选的 OS X 10.4 SDK。

API 文档可通过 OS X 的 AppleScript 编辑器(文件 > 打开词典)、appscript 的 ASDictionary 或其他第三方 AS 编辑器获得。如果安装了 ASDictionary,您还可以使用 appscript 的内置 help() 方法以交互方式浏览字典。

然而,可编写脚本的应用程序的 API 文档是出了名的不足,因此还需要充分了解 AppleScript 的一般情况和应用程序脚本的具体工作原理。 Apple 自己的 AppleScript 语言指南 描述了涉及到的各种功能,但没有过多提及如何将它们投入实际使用;如果您愿意花一些钱,可以找到几本好书(免责声明:我自己刚刚与人合写了一本)。

并期望通过在线文章、讨论论坛和现有脚本进行大量挖掘以寻找线索。 Doug's AppleScripts for iTunes 是 iTunes 脚本的重要来源。当然,它们是用 AppleScript 编写的,但其中许多都可以在 AppleScript Editor 中阅读,因此是很好的提示来源,如果您使用 appscript,则可以使用 ASTranslate 将 AppleScript 语法转换为 appscript 语法作为起点写你自己的。

If you're having problems with py-appscript, please contact the author (that'd be me) to troubleshoot it. Include information on Python installation(s) being used, Xcode version, and whether or not the problem is specific to appscript or affects all third-party modules or third-party modules with C extensions. Also, if you're using a python.org framework build rather than the built-in Python, make sure you have the optional OS X 10.4 SDK installed.

API documentation is available through OS X's AppleScript Editor (File > Open Dictionary), appscript's ASDictionary, or other third-party AS editors. If ASDictionary is installed, you can also use appscript's built-in help() method to browse the dictionary interactively.

Scriptable applications' API docs are notoriously inadequate, however, so a good understanding of how AppleScript in general and application scripting in particular works is also necessary. Apple's own AppleScript Language Guide describes the various features involved, but doesn't say much about putting them to practical use; there are several good books available if you're willing to put down some cash (disclaimer: I've just co-written one myself).

And expect to do a fair amount of digging through online articles, discussion forums and existing scripts for clues. Doug's AppleScripts for iTunes is a great source of iTunes scripts. They're written in AppleScript, of course, but many of them can be read in AppleScript Editor so are a great source of tips, and if you're using appscript you can use ASTranslate to convert from AppleScript to appscript syntax as a starting point in writing your own.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文