Skip to content

Instantly share code, notes, and snippets.

@robotsandcake
Created May 14, 2017 10:02
Show Gist options
  • Select an option

  • Save robotsandcake/901603938426f288f7cf213c21c8fa37 to your computer and use it in GitHub Desktop.

Select an option

Save robotsandcake/901603938426f288f7cf213c21c8fa37 to your computer and use it in GitHub Desktop.
In conjunction with the application Growl, this AppleScript will show information about the currently playing track in iTunes.
set crlf to (ASCII character 13) & (ASCII character 10)
set escapeChar to ASCII character (9)
tell application "Growl"
-- Make a list of all the notification types
-- that this script will ever send:
set the allNotificationsList to {"iTunes Playing Track"}
-- Make a list of the notifications
-- that will be enabled by default.
-- Those not enabled by default can be enabled later
-- in the 'Applications' tab of the growl prefpane.
set the enabledNotificationsList to {"iTunes Playing Track"}
-- Register our script with growl.
-- You can optionally (as here) set a default icon
-- for this scripts notifications.
register as application "Growl iTunes Notification" all notifications allNotificationsList default notifications enabledNotificationsList icon of application "iTunes"
set title_text to "Nothing playing"
set body_text to ""
set has_artwork to false
tell application "iTunes"
if player state is playing then
set trck to current track
if artworks of trck is not {} then
get artwork 1 of trck
set pic to data of result
set has_artwork to true
end if
get name of trck
set title_text to result
get artist of trck
set body_text to body_text & "Artist:" & escapeChar & result & crlf
get album of trck
set body_text to body_text & "Album:" & escapeChar & result & crlf
get time of trck
set title_time to result
set body_text to body_text & "Time:" & escapeChar & result & crlf
get rating of trck
set rate to result / 20
set body_text to body_text & "Rating:" & escapeChar
repeat rate times
set body_text to body_text & " * "
-- set body_text to body_text & " * "
end repeat
end if
end tell
if has_artwork then
notify with name "iTunes Playing Track" title title_text description body_text application name "Growl iTunes Notification"
else
notify with name "iTunes Playing Track" title title_text description body_text application name "Growl iTunes Notification"
"iTunesLibraryPlaylistIcon.icns"
end if
end tell
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment