pollytunes: yet another appscript scripting example

As you might already know I completely fell in love with appscript, a high-level, user-friendly Apple event bridge that allows you to control scriptable Mac OS X applications using ordinary Python scripts. I like it far better than Apple’s newly introduced Scripting Bridge, as appscript’s approach is much more Python-like and results in short and sweet code.

Just compare the following code snippets to understand me:

[center]ragtime = app(u’/Applications/RagTime 6.app’)
vs.
ragtime = SBApplication.applicationWithBundleIdentifier_(“de.ragtime.ragtime”)[/center]

The first expression is written using appscript, the second using Scripting Bridge…

Lately I invested some time and used appscript to rewrite one of my very old iTunes AppleScripts and I can tell you that it was pure fun. And in order to spread the word for appscript and to show felllow Mac users, how easy and enjoyable it is to write scripts with it, I decided to share my little script with you:

[center]pollytunes.py - current iTunes status as a spoken phrase
(To use this script, you need to install appscript on your Mac…)[/center]

pollytunes frequently checks the current iTunes status and then creates an AIFF audio file containing the current status as a spoken phrase. By default, this audio file is saved on your desktop named as ‘pollytunes.aiff’, but this - like other parameters - can be easily changed within the source code of pollytunes.

For example, if iTunes is currently not running on your Mac, it will create an audio file saying:
‘Sorry, iTunes is currently not running on my Mac.’

If you are currently listening to Foundations by Kate Nash, it will create an audio file saying:
‘I am currently listening to Foundations by Kate Nash from the album Foundations - EP.’

♫ Listen to sample output from pollytunes ♫

To use the script, just download it to your Mac and execute it in a Terminal window like follows. Of course you have to alter the command according to your environment:

python /Users/yourname/Desktop/pollytunes.py

Don’t be scared by the output the script generates in your Terminal window, it will look much like shown below:

The source code of the script already includes example code to upload the created pollytunes.aiff file to a web server, so that you can tell the world, what is currently playing in your iTunes.