we get signal

2007-01-31

a iTunes REPL

(tags emacs, iTunes, COM, Ruby)

While trying to figure out those playlist sorting order, I came across something nifty, but perhaps not so surprising. Since Apple provided the iTunes COM for Windows SDK , that means any programming language that implements Component Object Model (COM) can interface with iTunes and do programatic things. The documentation mentions the usual Windows scripting languages (Visual Basic, VBScript, JScript, Perl). But I do Ruby here. Interactively.

Emacs hosting a Ruby REPl session through irb, interfacing with iTunes

What are we looking at here? Well, Emacs (called Meadow here), is running an "inferior" (child process of Emacs)Ruby  in one of its buffers. This Ruby is running a REPL (Read Eval Print Loop) session called irb. From there, through a command line like interface, I grab a COM interface to iTunes and figure out how many tracks I have, how many times I've played my favorite song, the last time I played it, and when I added it.

A REPL can be a lifesaver. In the seminal Practical Common Lisp book, the second chapter is dedicated to the introduction to the language with a hands on REPL session. It even mentions the ultimate remote debugging situation, debugging software problems on the Deep Space 1 spacecraft live via REPL, no doubt appealing to its usefulness.

This interface is helping figure out that playlist sorting order by helping me create a script which will create a bunch of playlists, about 196 in all. More details another time.

(Those Ruby observant will notice I did a "puts favoriteTrack.Location" instead of "favoriteTrack.Location" and let irb try to print it. If I did so, the string is printed as garbage because Ruby does not convert the answer from UTF-16. "puts" lets Windows do it for us.)