Mar 29 2008, 22:43
(2012-12-26: There's a new version of this script for the new beta Last.fm desktop client. It's much better!)
I just wrote my first AppleScript
The problem: I found myself doing too much pointing, clicking, and thinking to do the following things:
- Rate the currently-playing track in iTunes
- Tell Last.fm that I "love" the track if I've rated it 4 or 5 stars
AppleScript to the rescue!tell application "iTunes"
set rating of current track to 100
tell application "Last.fm" to activate
tell application "System Events"
tell application process "Last.fm"
click menu item "Love" of menu "Tools" of menu bar 1
click menu item "Hide Last.fm" of menu "Last.fm" of menu bar 1
open location "x-launchbar:hide"
The first bit is fairly simple... iTunes stores ratings as a number 0 to 100, so rating a track as 100 means 5 stars.
The next part is a bit tricky, because the Last.fm application doesn't listen to AppleScript commands directly. Instead, we have to tell the OS to click the menus and whatnot that Last.fm owns. You can find more info about scripting "unscriptable" applications here
Finally, that last bit is in there to tuck away the LaunchBar
app that I use to run the script.
LaunchBar kicks ass... it keeps track of all of your applications, documents, music, scripts, and a bunch of other stuff, and lets you get to just about anything with a couple of keystrokes. It looks things up by abbreviations.. so, I've saved that script as 'Rate 5 Stars', so I can run it by hitting command-Space (which brings up LaunchBar) then R-5 ("Rate 5").
That's MUCH faster tracking down windows and clicking menus and stars... so, yay me :)