ITunes Apple Events API

I want to control iTunes via Objective-C (I just can't get Python installed correctly appscript

on my OS / X 10.6.3 system ... that would be my first choice).

From what I'm collecting IPC on Cocoa is based on Apple Events : Is there:

  • ITunes / Apple Events API Online Documentation
  • Instrospection mechanism for accessing iTunes API?

I am aware of the Applescript / Open Dictionary editor functions, but cannot figure out how to translate the information I see into IPC calls.

Note. I've already tried working out a solution via PyObjC, but the main function I'm working with is track search, which I can't figure out.

Disclaimer: OS / X is super new here.

+2


a source to share


2 answers


Do you consider using a scripted bridge ? It is built into the OS and also works with PyObjC. There is no specific search API, because the search is built into AppleScript ( whose sentences ) are mapped to the NSPredicate in the 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 are new to AppleScript, I highly recommend the Script Debugger Dictionary Explorer .

+11


a source


If you have any problems with py-appscript, please contact the author (that's me) to fix it. Include information about the Python installation you are using, the Xcode version, and whether the problem is appscript specific or affects all third party modules or third party modules with C extensions. Also, if you are using python.org framework build and not embedded Python, make sure that you have the optional OS X 10.4 SDK installed.

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



Application scripting APIs are notoriously inadequate, so you need to have a good understanding of how AppleScript in general and application scripting in particular work. The Apple AppleScript Language Guide describes various features but says little about how to use them for practical use; there are some good books if you are willing to give cash (disclaimer: I just wrote one).

And expect to make a lot of money in online articles, discussion forums, and existing script for tips. Doug AppleScripts for iTunes is a great source for iTunes scripts. They are of course written in AppleScript, but many of them can be read in the AppleScript editor, so this is a great source of advice, and if you are using appscript, you can use ASTranslate to convert from AppleScript to appscript syntax as a starting point in writing.

+3


a source







All Articles