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. Hey Otto, I just came across this post via ‘EvilLyrics’ forum, and noticed that all the links to your Scripts are dead. I was just curious if you still have them laying around anywhere or archived? I just recently got an iPod video, and a more simple (and possibly automated) way of importing lyrics to each song would be much appreciated. That is, if your scripts work with the latest iTunes 7.0.2.

    Thanks and Take Care,
    QW

  2. I can not figure out how to run the scripts. I have saved the file to my computer ( C:\Scripts ) and have Windows script Host opened in a cmd window, but I just can’t get the script to run. I’m pretty clueless when it comes to scripts but I really want to run the NolyricsPlaylist one. Can you offer any advice to a newbie.

  3. There’s really nothing to it. Rename the scripts from .txt to .js then double-click them in explorer, like you’d run any other program. You don’t need a command window open unless your configuration is all screwed up. The windows scripting host will run automatically since it’s associated with .js files by default.

  4. Then your computer is broken. You’ve misassociated JS files with notepad, somehow. Associate them to open with wscript.exe instead.

  5. Hey Otto,Didn’t know that this was possible, awesome!I’ve been looking for a way to create a playlist for each album. In other words, every track that belongs to an album will go into a playlist called “artist – album”. This doesn’t exist for Windows! But there are a few solutions for OSX like this one: ( http://www.dougscripts.com/itunes/scripts/scrip… ), which doesn’t help me.Can you write, or help me write, a script that does this?Thanks,Seena

  6. Hey Otto,

    Nevermind! One of the sample scripts in the iTunes Windows COM SDK does exactly this (I’m sure you already know).

    Thanks,
    Seena

  7. Lynn:

    I think you are having the same prob that I was. I originally saved the files as .txt’s. Then when I renamed them they were like this FindDeadTracks.js.txt. The only way that I could figure to change them to just FindDeadTracks.js was in the cmd window.

    Easiest way to do this: Put the files in your root directory, just C:\, not C:\Scripts. at the cmd prompt type: ren FindDeadTracks.js.txt FindDeadTracks.js

    Then you should be able to double click and they will run. I hope that helps, let us know if it doesn’t.

  8. hey otto, i want a programme that saves all my ratings and id tag info? cant seem to find it on ur site….can u point me in the right direction?

  9. What I would really like is a batch script to change the Video kind. I know applescript has this and its easy to find it on google.

    please! please!

  10. Also, it would be nice to be able to change the play count to a user specified number. Again this can also be done with apple-script.

    please! please!

  11. I would like to use a script to add a transcoded TV show to iTunes. Once the work is done, I want to tell iTunes to import the file and provide it some information about the show. Should I be looking in the COM SDK for ideas on how to do this? Is it even possible? I know there are C++, C#, and other ways to do it but I just want to create a simple script and not go through all that development work.

  12. Everything that you can do in C++ or C# and such, with regards to iTunes and the COM SDK, can also be done through javascripts or vbscripts. So yes, reading the COM SDK’s help file and looking through some of my scripts would be an excellent start to automate your iTunes usages.

    RC: in your case, I would look closely at the LibraryPlaylist object and the AddFile function within it. After you add the file to the main library, you’ll have to search through it to find the new Track listing for it (which may be harder than you think, especially if you have iTunes actually organizing your library), and then you can use the Track object to change any of the parameters for that entry.

    If you actually want to automate your transcoding itself, and you use iTunes to encode files, then consider the ConvertFile and ConvertFile2 functions in the main iTunes object. Also examine the Encoders and the OperationStatus objects.

  13. Hi Otto,

    Your scripts for windows based iTunes are amazingly helpful. There is one thing that I have been really in dire need of however, that maybe you could help me with. I know the current version of itunes has a feature that shows duplicate tracks (It searches by name of track and artist), but that also means songs on different albums are considered duplicates. I have about 95 gigs worth of music, so going through all of them would be quite tedious, I’ve been searching for a script that’d be able to locate (and preferrably delete) the duplicate tracks if they have the same track name, artist, AND album… Your help is very much appreciated, so far I’ve only found one solution, and it’s software that costs money that I just don’t have.

    Thanks in Advance.

  14. Hi Otto,

    Very cool work, didn’t realize iTunes could be scripted in Windows…is it possible to replicate the ‘append to comments’ script found on Dougs Applescripts? I use this heavily on my Mac to tag songs and create smart playlists.

    Thanks!

  15. Um otto, I have never done anything like this before. I just copy the whole thing and re-tag it as a .js in the folder that it tells me to in the second line?

  16. For the one hit wonders… is there any way that you can make it depend on the album only appearing once as opposed to the artist? Would I jst change all of the bits that say artist in note pad to album?

  17. Hey, great job and thanks for the hint, just wondering if there´s a way to delete the lyrics of just one playlist, hope you can help me. Cheers.

  18. Hi Otto,

    What I like most about your scipts is that they are practical in the true sense of the meaning. I’ve ssen too many gadgetry so far.

    Do you have a solution to customize the way iTunes is renaming files or even a standalone tool for this? I would like to rename some WAV files (no ID3 tags, obviously, but full Gracenote information imported into the library) based on the information in the iTunes XML library (!). If I do not find a solution for that, these files will be buried in my library … manual renaming would be time consuming.

    Regards,
    Christian

  19. … it seems that there are AppleScript Solutions available from Dougscripts: see “renaming files” and “file renamer”

  20. alright, im a total newbie at this whole scripting thing, and im sorry for my stupidity in advance. im trying to use the evillyrics import script. ive changed the .txt file to a .js file on my desktop. i run it the .js file, but i dont think its working right. it only seems to import songs one at a time, as i listen to them. i have both itunes and evillyrics open. after a while a small window shows up telling me it has “added lyrics to 1 song”. what am i doing wrong? or is it supposed to go slow like this?

  21. hey thanks a lot for that “find dead tracks” script.

    thats has made my search in my over 11.300 song database easy as something what is easy to do.

    greetz conan troutman

  22. Thank you so much for the scripts!! Really awesome. This is what I’ve been looking for for ages! I first this library-not-registered problem but just like with some girl in the evillyrics forum it was only because of itunes which was not installed properly. It now works fine! So thanks a lot!

  23. Someone above asked for an “append to comments” script. For example, if you wanted to sort by filename, you could use this script to take the Location property of all _selected_ songs and put it into the Comment field. Note: this overwrites all comments that might already be in there. This can be easily modified to put in any other piece of information you want, if you know the available properties (which are listed in the SDK). Just replace “currTrack.Location” with the property of your choice. This isn’t as fancy as Doug’s, but it should get you started on the right “track” (pun intended!).

    var ITTrackKindFile = 1;
    var objApp = WScript.CreateObject(“iTunes.Application”);
    var tracks = objApp.SelectedTracks;
    var numTracks = tracks.Count;
    var i = 0;

    while (numTracks != 0)
    {
    var currTrack = tracks.Item(numTracks);

    if (currTrack.Kind == ITTrackKindFile)
    {
    currTrack.Comment = currTrack.Location;
    }
    numTracks–;
    i++;
    }
    WScript.Echo (“File location added to Comments field for ” + i + ” tracks.”);

  24. That same basic code snippet can be changed to allow you to modify things like Skip Count and Video Kind, by replacing the following line:

    currTrack.Comment = currTrack.Location;

    With one of the following, respectively:

    currTrack.SkipCount = 0;

    currTrack.VideoKind = x;

    The enumerated values for VideoKind (replace for x) are:
    0 = None
    1 = Movie
    2 = Music Video
    3 = TV Show

    (This can’t be changed if it’s a purchased video.)

    Remember to save as a .js file, and have some tracks selected in iTunes when you run it.

  25. “Library not registered” = Reinstall iTunes. iTunes sometimes fails to register itself as a COM object. Reinstall it and these scripts will then work.

  26. I don’t know what the “find dead tracks”-script exactly does, but when I click ‘collect library’ in the advanced menu (don’t know the exact name in English), I get an overview of the dead tracks as well. Can’t remove them with one click though…

  27. I’m trying to use your update file as instructed but I keep getting a Windows Script Host dialog box stating: ”
    with a syntax error, code: 800A03EA, Microsoft JScript Compiling error at Line 1, Char 1.

    Any ideas of what I’m doing wrong?

    Thank you.

  28. Do you have anything that put all the songs from the same artist into playlist.
    ie, eveything from Gomez into a playlist has eveything with Gomez in it
    Cheers

  29. Hi Otto,
    From your script: Reload/update all songs in the library from the file tags
    Can you give an example of the file tags?

  30. John: MP3’s and other files have what are called “tags” in them that stores the information like the name of the song and artist and so forth. If you use some other program to manage those tags, then the update script makes iTunes notice changes to those tags.

  31. Hi Otto,
    Thanks for your quick reply.

    OK. Then can a script be written that updates the song info
    in itunes from data in a *.csv file.
    The name of the song can be in the first field and the rest
    of the info (artist, album, etc) in the following fields.
    And yes this is particularly useful for *.wav songs imported
    into itunes, not ripped from a CD.

    Thanks for your help,
    John Mahoney

  32. Hi Otto,

    Can a script be written that would import
    songs into itunes from a list in a file that
    contains the full path name of each song.
    Please add this to my wish list.

    Thanks for your help,
    John Mahoney

  33. Hi Otto,

    I’ve done a lot of programming but never in javascript are the 2 scripts I talked about
    doable and maybe spend some time learning the code? Or are they imposible and I’d
    just be wasting my time?

    Have any suggestions?
    John Mahoney

Leave a Reply

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

css.php