开发者

pyobj access to iTunes application

Let's say I managed to get the dictionary opened for iTunes in the Applescript editor:

pyobj access to iTunes application

How would I access the "search" commands usin开发者_运维问答g 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!


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜