Somebody on digg mentioned AppleScripting iTunes on the Mac, but it seems to be less well known that you can write Javascripts or VBScripts for iTunes for Windows.
So, here’s a bunch of scripts I’ve written for various tasks:
- Creates a playlist of all the songs in the library with no artwork: http://ottodestruct.com/itunes/NoArtPlaylist.txt
- Creates a playlist of all the songs in the library with no lyrics: http://ottodestruct.com/itunes/NoLyricsPlaylist.txt
- Creates a playlist of all the songs in the library of which you only have one of them by that artist (one hit wonders): http://ottodestruct.com/itunes/onehitwonders.txt
- Imports lyrics from EvilLyrics’ into iTunes: http://ottodestruct.com/itunes/EvilLyricsImport.txt
- Removes all lyrics from all songs in your library: http://ottodestruct.com/itunes/ClearLyrics.txt
- Reload/update all songs in the library from the file tags (useful if you use another tagging program to make changes to tags): http://ottodestruct.com/itunes/update.txt
- Finds dead tracks in your library and makes a list of them: http://ottodestruct.com/itunes/FindDeadTracks.txt
- Removes dead tracks from your library (this one was actually written by Apple originally, I’m just including it for completeness): http://ottodestruct.com/itunes/RemoveDeadTracks.txt
I’ve written more, but these are the most general purpose ones.
To use any of them, just download them, rename them to a *.js file, then run them like any other program (double click, select and press enter, type the name from a command prompt, etc). If you have all the defaults in XP or have the Windows Scripting Host installed on other Windows boxes, then the wscript.exe program actually runs the scripts, much like cmd.exe runs batch files. Same idea, anyway. The scripts connect to iTunes as a COM object and use it in that fashion. Works really well and is quite handy for scripting tasks in iTunes. Yeah, it doesn’t actually integrate or anything, but it’s still useful.

Hi Otto.
When I run your script, I got this error: “WScript.CreateObject – Could not locate automation class named iTunes.Application”. Error code: 80020009.
I use iTunes 7.6.1 and Win Xp2. In my registry do not exist the Class iTunes.Application. In regedit (HKCR), I found: IpodManager Class, ItunesDevices Class, ItunesService Class, ServiceDiagnostics Class and iPodUpdaterInterface Class.
Any ideas? Thanks.
I am just wondering if you have ever successfully added file/track thru the iTunes COM/Script to iPod Shuffle?
From iTunes SDK, there is AddFile() function to the LibraryPlaylist out of iPod source. It works for most of iPod devices, but to iPod Shuffle, AddFile() function will return 0xA0040203 (ITUNES_E_OBJECTLOCKED)!
Any idea about this?
Or do you know of any other function such as “Autofill” for iPod Shuffle?
Thanks.
evillyrics js..
seems to work only for some songs. i downloaded a night of lyrics with evillyrics and
then run the script to automatically write the lyrics into the tag. only 22 song over
3 hundreds. ..even if the updateall is set to true.
what can i do to make the script running?
aldo: The evil lyrics script is not needed anymore, the evillyrics program now supports talking to iTunes directly. Use that.
I have just used your “one hit wonders” script. Fantastic. It does exactly what it says on the tin. Thank you.
has any one come across this error that billox mentions above?
“WScript.CreateObject – Could not locate automation class named iTunes.Application”. Error code: 80020009.
I am also getting this and have tried uninstalling and resintalling numerous times (even older versions) but it has not fixed…
I wrote some scripts which makes itunes useful for me, but with them not working it’s completely useless.
Dale.
tinman: That problem only has one cause and one solution. The cause is an incomplete iTunes installation. The solution is a complete removal and reinstall of iTunes. Sometimes you can get it working by simply installing iTunes over itself.
However, since you’ve tried that already, you’re probably out of luck, because that is the only answer to your problem.
so is there no way to register the automation class manually?
(sorry if that’s a stupid question)
otherwise.. I guess I have to pray that the next version of itunes (which shouldn’t be far), will fix it.. but I don’t have high hopes!
If there is a way to do it, then I don’t know what it is.
Reinstalling iTunes has always fixed it in all the cases I’ve seen.
Hi. I’m very new when it comes to all of this and i’ve been running AtomicParsley to edit specific tags which you normally can’t accomplish in editing within iTunes itself. The only one left for me is to edit/add LongDescription for my movies in iTunes. I’ve looked everywhere and i can’t find a solution. I downloaded iTunes COM Windows SDK but have no idea how to handle it or how to write those jscripts to edit the longDescriptions which i’ve desperately been trying to achieve. If anyone can write this script for me or at least give me the tutorial on how to accomplish this then please i beg of you to help me. You can contact me by e-mail aswell (cesar_belifs@hotmail.com). I’ve really been trying to find these answers for 2 whole days now 24/7 with no luck at all…i’m using Windows XP. The short description i’ve accomplished which can be edited with AtomicParsley but to edit the long description is a no go for me, the one you can read when you click on the (i) button on the description field on itunes. Please help me on this one. I’de be most thankful for it!
Do you know if they changed things in the latest iTunes 7.7? I had “borrowed” on of your scripts for loading TV shows to iTunes via a batch script. Everything was working great and now I get and error (after upgrading itunes) which says “library not registered”. I have the following two lines in the script.
var ItunesApp = WScript.CreateObject(“iTunes.Application”);
var mainLibrary = ItunesApp.LibraryPlaylist;
I don’t know much or anything about jscript so I’m looking for help from resources I’ve found in piecing together the script that was once working.
Thanks … any help would be appreciated.
I used your scripts on an XP machine with itunes 7.7 and it worked perfect!
BUT I have my main machine running Vista and it does not work. Do you know how I can edit the code to get around this:
“could not locate automation class named “itunes.application”
Have you found a fix for Vista?
Ryan, Nik: You cannot “get around” those errors. The error basically means that iTunes is not installed properly. Try reinstalling iTunes.
Sorry Otto but I have a different opinion. I ran into the same problem as Ryan a where after upgrading to iTunes 8 the “NoArtwork” script was producing a “could not locate automation class named “itunes.application” error.
All I did to fix it was to to run an iTunes “Repair” on Vista’s Programs & Features. After this the script worked again.
I don’t use Vista and have no idea what you’re talking about in that regard.
On XP, reinstalling works and has worked for many people.
Do you have a script that will allow you to put a group of files (mp3s) into the podcast directory without subscribing to an rss feed?
Hey otto,
My music is currently stored in a stupidly named folder as I was only testing out iTunes at first. One thing led to another and I’d spent hours and hours getting all the tags perfect with all artwork showing nicely.
Now I want to move or just rename the folder but with iTunes being an Apple product it’s not so straight forward.
I have the database moved over to a sensible location and artwork/metadata intact but of course now it can’t find my music in it’s new location.
I was wondering if it’s possible to modify the RemoveDeadTracks script to update the location path, so something like this:
if (currTrack.Location == “d:\Music\blah*”)
{
currTrack.Location = “new path”
}
Is something like that possible?
Thanks
brendan: iTunes can do this itself. Just choose the “Consolidate Library” menu option. It’ll move all your library files into the iTunes library folders and rename them according to their tags and everything.
Thanks for this! I have been looking for something to do this for ages. Now I am no expert with all this scripting business, so I have some amateur questions. When I run should it open cmd and just do it’s thing? Do I know when it’s done or when I have added music and want to get lyrics what will happen?
Thanks again.
If you run one of these scripts from Windows, then it will run in wscript.exe, which has no interface at all. So no command window will normally pop up.
Otto thanks for your script work. I’ve Itunes 8. I’ve severals dead tracks on my ipod, but when i run your script, I recieve the messages “No dead tracks were found”. Maybe it’s not compatible with itunes 8 (also I update the software of my ipod). Thanks Indeed
Same as the previous user Otto, I am getting Windows Scripting errors with the latest iTunes, iTunes 8.0.
Just discovered your scripts and I must say that your scripts are fantastic. So fantastic that I’ve decided too write one of my own but thought I’d ask you before I start, if what I want to do is possible. I don’t want to waste time only to find out that it’s impossible anyway.
Say I have added 1000 tracks to my library today, and they are all still checked. I want to automatically create a series of playlists that contain a maximum of 99 randomly selected tracks each from those checked tracks. A track must only appear in one of the playlists, and not in any others.
I can get Smartlist to randomly select 99 tracks from the tracks added today, but if I make another playlist using the same criteria, I get a smattering of tracks that appear in the first playlist. Am I wasting my time? Do you have any advice?
Cheers Ross
You can do that with Smart Playlists, no scripting needed. Just make a new rule on the playlist saying that the tracks can’t be in the other playlist.
Thanks for the suggestion – I didn’t know that Smart Playlists could do that. In fact I don’t know how to do what you suggest! Could you give me an example? I don’t know how to say “tracks not already in an existing playlist”. I’m such a loser.
Thanks Ross
Look at the “Playlist” rule. Specifically, the “Playlist is not whatever”.
Hey Otto, Any chance of writing a script to locate unauthorized songs?
I’m not even sure how exactly you could do that. iTunes does not know if a song is authorized or not until it tries to play it, and then it just asks for the password to the account.
Otto,
I have the same question as brendon, posted 28th July. However, I have formated my hard disks and completed a clean install of windows. Before I did this, I backed up all my music and itunes files to an external hard disk.
I have now reinstalled itunes and put music back on hard disk. However, itunes can’t find the music in it’s new location. My old itunes library is now on the new install. Is there a script which will alter the file path of the ‘dead tracks’? I have 30GB of tracks so doing it manualy is not a realistc option.
Your help would be appriciated.
Thanks
Matt
Hello,
I ‘upgraded’ my itunes and it wiped out my playlists. On the Apple forum there is mention that you have a javascript that can get my playlist back from the ipod_control folder. I can’t seem to find this on your website and the link in the forum is broken.
I don’t necessarily need the songs transferred. All I really need is the names of the songs and the order. I can always recreate the playlist.
Thanks in advance.
Heidi
Any comments I may have made on that subject was at least 2 or 3 years ago, and those scripts no longer work, which is why they’re not here. I don’t write these sort of scripts anymore, much.
But they’re not hard to create yourself. Examine the sample scripts I wrote above, read the iTunes COM SDK document, and make one up yourself. It’s easy to do.