Context here is that I'm trying to abandon ship on Quicksilver on account of its oldness, staleness, and general decrepitude, but since I used it for such a weird variety of stuff, I'm having to get a little creative on how to replace it. In this case, I'd rigged QS to throw a Growl alert describing the currently playing track in iTunes whenever I whacked a certain hotkey, and since I wasn't interested in running a whole extra app just for that, I figured I could probably roll my own thingamabob and trigger it with FastScripts.
I figured right! And here's the goods:
tell application "iTunes"
set trackName to name of current track
set trackArtist to artist of current track
set trackAlbum to album of current track
set trackRating to rating of current track
if artworks of current track is not {} then
set trackArtwork to the data of artwork 1 of current track
set hasArtwork to true
else
set hasArtwork to false
end if
end tell
tell application "GrowlHelperApp"
(* register as application "iTunes Track Alert" all notifications {"Current Track"} default notifications {"Current Track"} icon of application "iTunes" *)
if hasArtwork is true then
notify with name "Current Track" title trackArtist & " – " & trackName description trackArtist & " – " & trackAlbum & " – " & trackName & " (" & (trackRating / 20 as integer) & "★)" application name "iTunes Track Alert" pictImage trackArtwork
else
notify with name "Current Track" title trackArtist & " – " & trackName description trackArtist & " – " & trackAlbum & " – " & trackName & " (" & (trackRating / 20 as integer) & "★)" application name "iTunes Track Alert"
end if
end tell
For reasons that are somewhat complicated, you'll have to paste that into AppleScript Editor and save it, then uncomment that one line, run the script a single time, and close the file without saving. After that, it'll work just fine, and you can set the display options for the alert in Growl's preference pane; the name of the application will be "iTunes Track Alert."
(Yes, I could have just left that line uncommented and skipped that extra step, but that seemed to make it run slower when I was testing it, and it really does only have to happen once.)
Incidentally, my hacked-up-in-an-afternoon-bullshit-AppleScript replacement for this feature turns out to be better than Quicksilver's version, because it shows the artwork even when it's not embedded in the file and can display the track's rating. Take that!
no subject
Date: 2010-09-12 06:40 pm (UTC)I might give it a shot later.
no subject
Date: 2010-09-13 12:47 am (UTC)Anyway, yeah, FastScripts. Free, lets you set keyboard shortcuts, can handle shell/perl/ruby scripts in addition to Applescripts, etc.
no subject
Date: 2010-09-13 04:30 am (UTC)no subject
Date: 2010-09-13 04:39 am (UTC)no subject
Date: 2010-09-13 04:44 am (UTC)What do you have your keyboard shortcut set to?
no subject
Date: 2010-09-13 04:49 am (UTC)(Is this the first time one of my Applescript snippet posts was actually useful for someone else? I IS A HELPER.)
no subject
Date: 2010-09-13 04:59 am (UTC)I wasn't kidding about wishing for this exact thing yesterday. Literally. I think I saw a Growl notification for something else, and I was like, "It'd be cool to be able to call that to see what iTunes is playing."
no subject
Date: 2010-09-13 05:07 am (UTC)no subject
Date: 2010-09-13 05:27 am (UTC)AAAAHAHAHAHA. Plus, I linked to some of these same songs on your journal a couple weeks ago.
ASDLFKJ FKJAKSJDF LK FKASDASF
Fine, so my collection isn't so big. There's about a 1/100 chance that a song by this guy would come on. But still.