views:

76

answers:

1

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

alt text

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!

+3  A: 

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.

Nicholas Riley
+1: Very useful! Thanks a lot.
jldupont