Now Hearing This

I added a sidebar to the front page here at onfocus that shows the last few albums (with cover art) I've listened to in iTunes. Let's skip why I might want to do this for now, and just jump into the how. People have been doing this since MP3 players have existed, and there are several services that can do this for you now. I send my tracks to, and there's My Strands—both of these services have HTML snippets you can add to your site that will show some aspect of what you're listening to. is great at putting together charts of tracks and artists, but does nothing with albums. So I had to code my own "now listening" widget to show recent albums. Here's how it works in case anyone out there wants to do something similar:
On My Server
My server has a Perl CGI script called getAlbum.cgi that accepts an artist and album name. Once getAlbum receives an artist and album, it searches for a match on Amazon via their API. If a match is found, it puts a little HTML together with the details, adds the album to a local HTML file: now-hearing.html, and removes the last entry. I include the file in my weblog, and that's what you see in the sidebar.
On My PC
With the server script in place, I just needed a little glue between the server and iTunes. A Windows script called now-playing.vbs checks to see if iTunes is open and playing, and then sends the current artist and album to the server. I set the script to run every 20 minutes with the Windows Task Scheduler. It doesn't grab everything that's playing (especially if I'm shuffling around), but it gets pretty close.
On My Mac
I use more than one computer, so I didn't want my Mac to be left behind. I set up an AppleScript that basically does the same thing as the PC script. Instead of using an outside process to run the script at regular intervals, I used the AppleScript idle handler to hit the server every 20 minutes. Then I set the script to open when I log in.
Here's the Code
If you want to try this setup, you can grab the code: You'll need to edit the scripts a bit so they're pointing to your version of getAlbum.cgi on your server, but that's about it. These scripts are working well for me, and they didn't take very long to put together. And hey, who else is going to play Toots and the Maytals back to back with Ladytron? These types of idiosyncrasies need to be put on display!
« Previous post / Next post »


Not related to your iTunes habits, but I'm thrilled to see you're reading one of my favorite books. I'd love to know what you think of The Name of the Rose.
Name of the Rose is fantastic--I just finished reading it a few nights ago. I normally don't read fiction, but I couldn't wait to read the book each night and be in the world of the abbey. I think it's a perfect book for a Web geek like me, because it touches on many of my pet issues like access to information, how authority uses information, and how we give meaning to information. In fact, the main character is sort of an alpha geek of the Middle Ages.
And the villain's name is a direct reference to an author who tackles many of the issues you mention. If you haven't checked out Borges yet, I highly recommend starting with his Collected Fictions.
I've started several books since finishing Name of the Rose, but none of them are quite right to follow. Thanks for the recommendation, I'll pick it up.
Hi! You're reading a single post on a weblog by Paul Bausch where I share recommended links, my photos, and occasional thoughts.

Search Results

No emoji found