iTunes Javascripts

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:

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.

143 thoughts on “iTunes Javascripts”

  1. 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.

  2. 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?

  3. Ryan, Nik: You cannot “get around” those errors. The error basically means that iTunes is not installed properly. Try reinstalling iTunes.

    1. 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.

  4. 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?

  5. 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

  6. 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.

  7. 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.

    1. 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.

  8. 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

  9. 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

    1. 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.

  10. 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

    1. 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.

  11. 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

  12. 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

    1. 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.

  13. I’ve read a few comments back and forth about comments field scripting and wondered if any final version of a script was ever created that would append comments (rather than overwrite) to a number of selected songs. iTunes 9.x on Windows actually broke the itunes.application, not a bad installation.

  14. Could not locate automation class named ‘iTunes.Application’.

    I still get this error in iTunes 9.x when running the append to comments script. I have COMPLETELY removed itunes, Bonjour, Quicktime, Apple Supports, yada yada yada from my machine and reinstalled. Still doesn’t work.

    Is there a .reg file or something I can load to get the automation class?

  15. Hi Otto,

    have you by any chance written a script that embeds automatically downloaded album artwork into the id3 tags of the files in my iTunes?

    Thanks for the other scripts, they really really helped to clean up my library 🙂

  16. I’m on Vista Home Premium, iTunes 10.0.1.22. I used to use scripts all the time, but since v9 or so of iTunes, I can’t. I have uninstalled iTunes with Revo to completely obliterate everything Apple. Defragged my registry, rebooted, reinstalled, and still the same problem – Windows Script Host Error 800200009
    “Could not locate automation class named “iTunes.Application”.

  17. Hello Otto! I was looking through the script for Nolyricsplaylist.js and I was wondering if it is possible to tweak the script in a manner that instead of the whole music library on my system, ONLY the tracks on my device -say “IPOD” are scanned for tracks with no lyrics. Could you please advise on this front?

  18. Hi Otto,

    Do you have an iTunes script for copying data from one field to another. Such as copying the songs “Name” to the “Sort Name” field.

  19. Great scripts, thanks for these. I used the Remove Dead Tracks script but will give the others a go too. I’m on Vista and it didn’t work at first but I tried Tony’s advice above and it worked (run an iTunes “Repair” on Vista’s Programs & Features).

  20. Thanks for the script to find dead files, it worked like a charm on windows 7 ultimate, and took seconds to find. Cheers to you otto. I had three bad files that kept stopping my sync process in itunes and it was driving me nutz! Cheers and props.

  21. This helped a ton. It is unbelievable and unacceptable that itunes still after all these years has no built in functions like that

  22. Hi,

    Just found this recently and have tried running your scripts on obviously much newer vresioins of all software, ie WIN 8.1 and iTunes 12.

    The One Hit Wonder script works pretty much as expected, but the single most handy script I’m looking to use doesn’t. Namely the finding lyrics script. Do you have an updated fix for this?

    Thanks in advance.

    J

  23. Itunes updated and renamed all of my files. Is there a script that will rename them back, and update itunes, to my preferred format? (artist\album\track – name)

  24. Otto,

    I have just discovered your site and am working on some things of my own as I don’t let iTunes organize my music. I am struggling to find the documentation for the object model. Can you point me in the right direction?

    1. I wrote this post 12 years ago. I haven’t used iTunes or pretty much any Apple products in almost a decade now. So, sorry, not really sure where their documentation would be nowadays.

Leave a Reply

Your email address will not be published. Required fields are marked *

css.php