In my previous article, Scripting iTunes with Perl - Part 1, I demonstrated how the iTunes COM object can be used with Perl. In this article I will be showing you how to catch events from iTunes. The example script below catches the ‘OnPlayerPlayEvent’ and then displays the cover art from the current track in a Tk window.
Computers can accumulate a large amount of dust and gunk in harsh environments. The pictures below are of an Apple Power Macintosh 8500. This computer was bought new in 1996. It was my primary computer in high school. When I moved out of my parent’s house I set it up for them to use. It spent a few years in a very dirty building; a building where dirty ethylene glycol is recycled into full strength automotive antifreeze. I suspect that most of the gunk we found in the case is from being in that environment.
Believe it or not this computer was actually running fine in this condition!
In this article I will explain how you can write Perl scripts which use the iTunes COM interface to control iTunes. You can download the iTunes COM SDK here. The SDK comes with excellent documentation and several example scripts. In this article we’ll be focusing on using the COM interface with the Win32::OLE Perl module.
The iTunes COM SDK was fist released with iTunes 4.5 and has been updated and enhanced with every major point release since. As I write this, the current COM interface version is 1.7, included in iTunes version 6.0.2.
The first script we that we’ll look at randomly selects tracks from your iTunes Library until it finds a track with artwork. When the script finds a track with artwork it will save it to a jpeg file.
This is the first post on the blog. I will be discussing technology-related topics here. In the next few weeks I’ll be writing about Asterisk and SIP phones, the amazing Parse::RecDescent Perl module, and a how-to on scripting iTunes with Perl.
Search
About
Pat Padgett formed CyberRazor LLC in the fall of 2005 with a commitment to assist businesses, large or small, utilize technology to it’s fullest potential to cut costs and increase profit. Read more about us.

