Learn to program your iPod with VBScript

Apple released an iTunes SDK with COM interfaces so folks at home could program their iPod or iTunes under Windows. The sample code used Javascript. I mistakenly thought that the Javascript would only run in a browser, but it turns out you can just type the complete name of the file into a CMD prompt and off you go.

But since I didn't know that, I developed some Visual Basic (VBScript actually) code that does some playlist operations. I was motivated to do this because my old 3G iPod had a bug where podcasts wouldn't show up under a Podcast tab, or under the Music tab. As a result, if the podcasts were not in a separate playlist, they would simply be impossible to delete. The first thing I wrote therefore was some code to take any iTunes audio file that wasn't referenced and put it into an "Unreferenced" playlist that I could then easily manipulate.

VBScript, interestingly, is pretty inferior to Javascript for working with COM objects. The main problem I ran into was that I couldn't make an array of objects, so I had to resort to a hack where I store a unique identifier for an object in an array, and then look it up when necessary.

I recently added some code to export a list of the music ratings in my library to a file; I found this was necessary because even though MP3 files have a rating ID3 tag, iTunes doesn't use it - the ratings are stored in iTunes local database. So I wrote a bit of code to write out the ratings from one iTunes library and some code to read them back into another iTunes library.

Anyway, I offer the "playlists" code to you, future iPod programmer. If you know anything about programming at all, you should be able to follow the logic in the code.

Have fun, and feel free to post comments or questions right here.

© 2008 Stephen Clarke-Willson, Ph.D. - All Rights Reserved.