Controlling Spotify through Applescript & Quicksilver.

2 minute read.

Update Available: http://www.jacktams.co.uk/2009/10/09/spotify-applescripts-updated/

picture-2I have almost solely being listen to music through spotify for the last couple of weeks, sure it doesn’t replace iTunes but its damn good at what it does, all you can eat music for free. http://www.spotify.com/

The Problem:
Spotify can use the built in shortcuts for play/pause, forward and reverse, but if like me you use a different keyboard and effectively ‘dock’ you Macbook its not much use. Enter Quicksilver, the perennial quick-launch and whiz-kid short-cutter for mac. http://bit.ly/yrlr7

I already have a load of triggers set up within quicksilver for everything from make an event in iCal to post a tweet or send email.

So getting Spotify in there, it turns out Applescript is here to help, using the System Events helper you can select a menu item without actually clicking it. Below is the code for the main actions you would want in Spotify. Simply save the apple script, then attach it to a trigger in Quicksilver. Hey Presto, magic! For more details on setting up triggers check the Quicksilver wiki, it explains it alot better than I ever could. http://bit.ly/134dnL

Play Next

tell application "Spotify" to activate
tell application "System Events"
   tell process "Spotify"
      click menu item 3 of menu 1 of menu bar item 5 of menu bar 1
   end tell
end tell

Play Previous

tell application "Spotify" to activate
tell application "System Events"
   tell process "Spotify"
      click menu item 4 of menu 1 of menu bar item 5 of menu bar 1
   end tell
end tell

Play/Pause

tell application "Spotify" to activate
tell application "System Events"
   tell process "Spotify"
      click menu item 1 of menu 1 of menu bar item 5 of menu bar 1
   end tell
end tell

Notes:
Don’t forget to activate assitive device support see http://www.macspeech.com/extensions/faq/kb.php?article=48