// 18.Oct.2009


I know that everybody and his dog has written an AppleScript for extracting currently playing track information from iTunes but, despite a little Googling, I didn't find any that exactly suited my purposes. So, naturally, I went and rolled my own.

Specifically, I wanted a script that would output a simple line of text that I could get on to my desktop with GeekTool. It was important to me that, along with Artist and Track information, I could also get a status indication (Is iTunes running? Is a track selected? Is it playing or paused?) Here's what I came up with:

-- MusicMate
-- Displays currently playing track from iTunes.
tell application "iTunes"
if it is running then
set now_playing to the artist of current track & ": " & the name of current track
if not my iTunesState() then
now_playing & " (paused)"
end if
on error
"iTunes: Waiting for track selection..."
end try
"iTunes: Not running..."
end if
end tell
-- Is iTunes currently playing or not?
on iTunesState()
tell application "iTunes"
if player state is playing then
return true
return false
end if
end tell
end iTunesState

I saved this script as musicmate.scpt into a folder called AppleScript in my Applications directory.

Then, in GeekTool, I've created a MusicMate group and configured it to execute the following Shell command:

osascript /Applications/AppleScript/musicmate.scpt | iconv -f utf-8 -t ucs-2-internal

The iconv part of the command ensures that the full range of UTF-8 character encodings are handled properly.

I've set a Refresh rate of 1 second (I want the display to be as near real-time as possible).

Works a treat!

Get the Source: Download MusicMate (4KB)

Last Revision: October 24th, 2009 at 11:12

Comments are closed.