Tyler Clemons

iTunes Scripting with Python

by on Aug.29, 2008, under appscript, iTunes, Programming, Python, scripting

I ran across scripting for the Mac OSX awhile ago. I finally decided to take a look at it when I decided to play around with Adium’s open source code. The most dominant prescene I observed was Applescript. Applescript is nice and all, but Python is nicer. Scripting OSX applications with Python has been around for a bit. Using the easy to install appscript, scripting can be leveraged by the power of Python and Ruby.

One of my favorite applications on my Mac is iTunes, so its no surprise this is the first application I turned to for testing. To start, import the proper library:

from appscript import *

Afterward, we can create a handle to iTunes and tell it to play:

itunes = app('itunes')
itunes.play()

Running the above lines will open up the application called iTunes and execute the action play.  It will play the current track and specific tracks can be passed as an argument. The action .stop() will stop iTunes. Of course, we can do so much more with appscript. For instance, we can create a playlist that only plays a specific album.  I wrote a script that does just that.

The script can be found HERE in a zipped file.

It is documented and should be easy to follow.  One more thing, it is also possible to assign values to each track as if they were normal data objects.

:, ,

Leave a Reply

Looking for something?

Use the form below to search the site: