Currently playing song in iTunes on command, revisited

Written . Tagged AppleScript, OS X.

[Screenshot]

The previously blogged Currently playing song in iTunes on command script has been updated.

It turned out Jacob Rus had made a similar script before mine, that did without saving cover art as a temporary file. I modified my code accordingly. It seems this also solved the strange problem that the script worked fine when run directly but sometimes not when run through Quicksilver.

Jacob’s script, along with others by him to e.g. quickly change rating or skip-and-display, are available here.

The script (download):

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
set theTitle to "Currently playing"
set albumArt to null
set doMusic to false

tell application "iTunes"
  if player state is playing then
    set theArtist to artist of current track
    set theSong to name of current track
    set theAlbum to album of current track

    try
      set albumArt to data of artwork 1 of current track
    on error
      set albumArt to null
    end try

    set doMusic to true
  end if
end tell

set appName to theTitle
set notification to theTitle
set myAllNotesList to {notification}

tell application "System Events"
   set isRunning to (name of processes) contains "GrowlHelperApp"
end tell

if isRunning then
  tell application "GrowlHelperApp"
    register as application appName  all notifications myAllNotesList  default notifications myAllNotesList  icon of application "iTunes"

    if doMusic
      set theDesc to "Track:\t" & theSong & "\nAlbum:\t" & theAlbum & "\nArtist:\t" & theArtist
    else
      set theDesc to "Nothing."
    end

    if albumArt is not null
      notify with  name notification  title theTitle  description theDesc  application name appName  pictImage albumArt
    else
      notify with  name notification  title theTitle  description theDesc  application name appName
    end if

  end tell
end if