June 8, 2007 at 4:09 PM by Dr. Drang
After a few weeks of pretty constant work and overwork, today has been something of a goof-off day. For reasons I can’t quite remember, I came across this post on Mac OSX Hints, which describes a way of taking the iTunes album cover art of the currently playing song and putting on your desktop through GeekTool. I already had GeekTool set up to display the name, artist, and album of the current track—described here—but this seemed like a fun addition. The lower right corner of my desktop now looks like this:
The text comes from my previous GeekTool arrangement, and the album art is from today’s additions.
The setup is basically that described in the OSX Hints article, but I made a few changes:
- The original AppleScript converts the art from PICT to TIFF. The first comment to the article mentioned that this was unnecessary, and I altered the script to keep the art in PICT format.
- The original used a transparent TIFF to display when there was no album art—as when iTunes is off or paused. With the change to PICT, I decided that the “blank art” file should be a single pixel file with the color of the pixel set to match my desktop color.
- The original AppleScript would show the album cover of the current track even when iTunes was paused. I wanted the blank art displayed when iTunes was paused.
- The original script seemed a repetitive when it came to showing the blank art, so I streamlined the logic a bit.
My version of the AppleScript, called “iTunesArtwork.scpt,” is kept in my
~/Library/Scripts folder and looks like this:
-- Paths and stuff set ArtworkFromiTunes to ((path to home folder) as text) & ¬ "Pictures:iTunes Artwork:From iTunes:albumArt.pict" as alias set iTunesArtwork to ((path to home folder) as text) & ¬ "Pictures:iTunes Artwork:From iTunes:albumArt.pict" set DefaultArtwork to ((path to home folder) as text) & ¬ "Pictures:iTunes Artwork:Default:albumArt.pict" set displayArtwork to ((path to home folder) as text) & ¬ "Pictures:iTunes Artwork:albumArt.pict" -- Unix versions of the above path strings set unixITunesArtwork to the quoted form of POSIX path of iTunesArtwork set unixDefaultArtwork to the quoted form of POSIX path of DefaultArtwork set unixDisplayArtwork to the quoted form of POSIX path of displayArtwork set whichArt to "blank" tell application "System Events" if exists process "iTunes" then -- iTunes is running tell application "iTunes" if player state is playing then -- iTunes is playing set aLibrary to name of current playlist -- Name of Current Playlist set aTrack to current track set aTrackArtwork to null if (count of artwork of aTrack) ≥ 1 then -- there's an album cover "Running and playing and art" set aTrackArtwork to data of artwork 1 of aTrack set fileRef to ¬ (open for access ArtworkFromiTunes with write permission) try set eof fileRef to 512 write aTrackArtwork to fileRef starting at 513 close access fileRef on error errorMsg try close access fileRef end try error errorMsg end try tell application "Finder" to ¬ set creator type of ArtworkFromiTunes to "????" set whichArt to "iTunes" end if end if end tell end if end tell if whichArt is "iTunes" then do shell script "ditto -rsrc " & unixITunesArtwork & space & unixDisplayArtwork else do shell script "ditto -rsrc " & unixDefaultArtwork & space & unixDisplayArtwork end if
I just updated the script to work with Snow Leopard. The line that sets the variable
ArtworkFromiTunes used to end
as file specification; now it ends
as alias. I think
as alias will work in Leopard, too, but I don’t have a good way to check right now.
I created a new “Shell” GeekTool entry to call this script every 10 seconds. The command is
It doesn’t produce any output, so the location, size, font, color, etc. of the output area doesn’t matter.
~/Pictures folder, I have a folder called “iTunes Artwork,” and its contents look like this:
The “albumArt.pict” file in the “Default” folder is the single-pixel PICT I mentioned before. If you want to use my version of the script unchanged, you’ll have to replicate this directory stucture and make a “blank art” file to match your desktop. Don’t worry about the other two “albumArt.pict” files; they’re created by the script when it runs.
I created a new “Picture” GeekTool entry to display the picture at Source URL
every 10 seconds (you’ll have to change the user name, of course). The script makes that file a copy of the album cover art if a track is playing (and has cover art) and a copy of the single-pixel “blank art” otherwise. The display area is 150×150 pixels and the Picture Style is set to display Proportionally in the lower right corner of the display area.
Because the text and the artwork are controlled by three separate GeekTool entries that don’t necessarily run simultaneously, it’s not uncommon for the text and artwork to be out of sync for a few seconds when a new track begins playing. I could make them more closely synced by reducing the time between GeekTool calls, but the delay isn’t annoying enough to bother.
The scripts described in this post may lead GeekTool to eat up more memory the longer it runs. You may want to also run my GeekTool memory monitor script so you can track GeekTool’s memory use and restart it when necessary.