What I'm Doing...

Subscribe

Search

Email

  • Memphis, TN 38103 U.S.A. Otto 240cf86e-5cad-11dc-8314-0800200c9a66

Buy Otto a Beer

Currency:

Amount:

Website(Optional):

Get Otto a Gift

My Amazon.com Wish List
Text

20 Oct 2005-10-20 11:01

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.

Tags: , , , , , , , , , , , ,

Posted in Geekery, Programmery | 121 Comments » -

121 Comments

  • Heidi says:

    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

    • Otto says:

      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.

  • Matt Batham says:

    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

  • Kevin says:

    Hey Otto, Any chance of writing a script to locate unauthorized songs?

    • Otto says:

      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.

  • Ross says:

    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

  • Ross says:

    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

    • Otto says:

      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.

  • Skates says:

    Same as the previous user Otto, I am getting Windows Scripting errors with the latest iTunes, iTunes 8.0.

  • 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

  • Bovril says:

    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.

    • Otto says:

      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 says:

    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.

  • brendan says:

    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

  • BorgSPeon says:

    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?

  • Otto says:

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

    • Tony says:

      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.

      • Otto says:

        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.

  • Ryan says:

    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?

  • Nik says:

    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.

  • Prod says:

    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!

  • Otto says:

    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.

  • tinman says:

    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!

  • Otto says:

    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.

  • tinman says:

    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.

  • peter says:

    I have just used your “one hit wonders” script. Fantastic. It does exactly what it says on the tin. Thank you.

  • Otto says:

    aldo: The evil lyrics script is not needed anymore, the evillyrics program now supports talking to iTunes directly. Use that.

  • aldo says:

    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?

  • Dale says:

    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.

  • billox says:

    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.

  • Anders says:

    Hi Otto.

    Is it possible to write a script that increases the playcount.

    It’s a feature that I’d like to use together with my Serato Scratch Live DJ-software.

    I’d want the playcount to increase when I play the track in SSL.

    Thanx
    /Anders

  • nik says:

    Otto… I’m trying to hack a script together that allows me to add tv shows (.mp4) into my playlist. I currently have the scipt working to with basic attributes but I want the script to check to see if the file I’m trying to add is already in iTunes.
    I need JScript help since the last time I coded was using “C and c++” back in the day.

    I’m getting a runtime error when it tries so search a collection when it can’t find anthing in the library already. So the first issue is: When a collection is blank as the result of a search is there a way to determine that before the code fails when using the enumerate statement?

    Second issue I’m having is when it has a valid collection,and I try to verify duplicates, it always matches even though the echo statement shows them not matching.

    Here’s the script:
    /*
    addToiTunes.js [video type: 0=music 1=movie 2=musicvideo 3=tv show] [Show] [Title] [AirDateTime]
    */

    var ItunesApp = WScript.CreateObject(”iTunes.Application”);
    var mainLibrary = ItunesApp.LibraryPlaylist;

    var file;
    var videoKind;
    var show;
    var title;
    var emumItems;

    if(WScript.Arguments.length > 0)
    {
    file = WScript.Arguments(0);
    }

    if(WScript.Arguments.length > 1)
    {
    videoKind = WScript.Arguments(1);
    }

    if(WScript.Arguments.length > 2)
    {
    show = WScript.Arguments(2);
    }

    if(WScript.Arguments.length > 3)
    {
    title = WScript.Arguments(3);
    }

    if(WScript.Arguments.length > 4)
    {
    epid = WScript.Arguments(4);
    if (title==”") {title=epid;}
    } //fix for null mediacenter episode titles, use AirDateTime

    WScript.Echo (”Before collection search”, show, videoKind, title);

    var colItems = mainLibrary.Search(show, 0);

    if (file)
    {
    enumItems = new Enumerator(colItems);

    for (; !enumItems.atEnd(); enumItems.moveNext())
    {
    var objItem = enumItems.item();
    WScript.Echo (”For Loop”);
    WScript.Echo (objItem.name, ‘****’, title);
    WScript.Echo (objItem.show, show);

    if (title = (objItem.name))
    {
    WScript.Echo (”Matching show already in Library – don’t Add it”);
    }
    else
    {
    WScript.Echo (”Add to Library”);

    var opStatus = mainLibrary.AddFile(file);
    while (opStatus.InProgress){} //wait until done
    track = opStatus.Tracks.Item(1); //quick and dirty
    if (videoKind)
    {
    track.videoKind=videoKind;
    }
    if (show)
    {
    track.Show=show;
    }
    if (title)
    {
    track.Name=title;
    }
    if (epid)
    {
    track.episodeid=epid;
    }

    }
    }
    }

  • Otto says:

    Still using replace incorrectly. replace doesn’t modify the string itself, it just returns the modified string in memory.
    Try this:
    var str = currTrack.Comment;
    str = str.replace("acoustic", "");
    currTrack.Comment = str;

  • johnPaulVaughan says:

    Thanks for the help Otto (It makes a lot more sense to me now). I created this script from what you suggested, brilliant but I must be missing something because it still doesn’t work – I’m not sure why… /* so close but yet so far */…

    var ITTrackKindFile = 1;
    var objApp = WScript.CreateObject(”iTunes.Application”);
    var tracks = objApp.SelectedTracks;
    var numTracks = tracks.Count;
    for (i = 1; i <= numTracks; i++)
    {
    var currTrack = tracks.Item(i);
    currTrack.Comment.replace(”acoustic”,”");
    }
    WScript.Echo (”The text has been removed from Comments.”);

  • PerfectVirus says:

    Otto
    Could you write a script that finda Duplicate songs but only if their title, artist and album are the same?

    iTunes has a decent “Show Duplicates” but it only seems to match artist and title.

    I have dozens of Greteast Hits albums only with the originals they were taken from and this makes using “Show Duplicates” rather tedious since I have to double check the album name too.

    I would still need to do some investigating to make sure which I would delete but at least the list would be shorter.

  • Otto says:

    johnPaulVaughan: Your problem is right here:
    var currTrack = tracks.Item(numTracks);
    That ain’t right. Also, it’s a weird way to write a loop. Using a while when you have a fixed number of tracks to go through doesn’t make any sense. Use a for loop instead. Like this:

    for (i = 1; i <= numTracks; i++)
    {
    var currTrack = tracks.Item(i);
    ...

    You won’t need to increment i or decrement numTracks this way.

    Another problem: What exactly is this supposed to do?
    if (storedComm.match(/, acoustic/i) == null)
    currTrack.Comment.replace (”acoustic”, “”);

    As written, that doesn’t make much sense. It’s searching for “(comma)(space)acoustic” in the comment, and when it does not find it (the == null part), it attempts to replace the word acoustic with an empty string. I’m not sure that is what you want to do. I think you’re wanting to find the word acoustic and remove it from the comment, yes? In which case forget the match, just do the replace directly.

  • johnPaulVaughan says:

    I should re-phrase… I took another fantastic script that appends to comments and f’ed it up.

  • johnPaulVaughan says:

    HI guys,
    Anyone have an idea why this script doesn’t work (I wrote it myself and can’t see what the problem is)

    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)
    {
    var storedComm = currTrack.Comment;
    if (storedComm.match(/, acoustic/i) == null)
    currTrack.Comment.replace (”acoustic”, “”);
    }
    numTracks–;
    i++;
    }
    WScript.Echo (”The text has been removed from Comments.”);

  • Daniel Aldous-Critchley says:

    Hi
    I have 611 songs in a playlist which were badly named during an import from an old mp3 player. The filename is currently in this format:

    00 – (Tag Missing) – Robbie Williams – Millennium

    and I want it to be

    Robbie Williams – Millennium

    There is no ID3 tagging in the mp3’s. Basically, what I want to do is TRIM the left 21 characters from the actual filename and obviously have itunes update its list too. Even better would be to read the next part of the filename i.e. up to the next ” – ” and add that as the artist tag.

    Is any of this possible??
    Thanks
    Daniel

  • username9876 says:

    Otto — Thanks very much. That works like a charm!

  • William Joyce says:

    Also, try http://www.microsoft.com/techn.....tunes.mspx for a good primer.

  • William Joyce says:

    I use the free ActiveX/COM inspector from oaklandsoftware.com to expose the iTunes COM interface.

  • Otto says:

    username9876: You can set the encoder, but not the bitrate. If you call IiTunes::Encoders, it will give you back an IITEncoderCollection. You can look through these to find the IITEncoder object you want, and then set it by putting it into IiTunes::CurrentEncoder.

    To put it another way:
    var iTunesApp = WScript.CreateObject(”iTunes.Application”);
    var encoderCollection = iTunesApp.Encoders;
    var encoder=encoderCollection.ItemByName(”AAC Encoder”);
    iTunesApp.CurrentEncoder = encoder;

  • username9876 says:

    Is there a way to call a particular iTunes encoder in a script? For instance, if I always want a particular script to use the AAC Encoder at 192 vbr, what line would I include in a script? Thanks very much.

  • Stuart says:

    Hi i was just wondering if there was a script where u could see how many times each artist has been played?
    Thanks

  • Andrew says:

    Hi Otto,

    Great scripts, real time savers, thanks!

    Just wondering if you know of a script that will create a playlist of all tracks where the song title contains words which start with a lower case letter. I would like to fix the tags of these tracks, but would rather alter them manually rather than it be automated as there may be some where a lower case letter is more appropriate.

    Thanks

  • [...] Javascript your iTunes — like Applescript for Windows! [...]

  • jorkel says:

    Hi Otto,
    is there a script out or any other way to merge/join a bunch of acc / m4a files into one? There’s stuff like that for mac users. I’ve tried to convert my files to mp3, but my mp3-merger chokes when I give him the converted files.
    Help is much apprechiated.
    Thx.

  • Quach says:

    Awesome Thanks Otto,
    These Scripts work great.

  • Otto says:

    Quach: Google for iTunes COM SDK. Then download it and read it. Simple.

  • Quach says:

    How do u figure out the var names?? Where did u go to find out what itnes uses for these names.
    ie:
    iTunes.Application
    iTunesApp.SelectedTracks
    iTunesApp.CreatePlaylist
    currTrack.Artwork.Count
    currTrack.VideoKind
    mainLibrary.Tracks etc

  • Otto says:

    No, iTunes does not provide that sort of access to those tags. You could use a program like MP3Fix or something to correct your bad length MP3 files.

  • Marlie says:

    Is there a script that would reset all tags or just the TLEN tags? I have a bunch of songs that are tagged so they have no duration.

  • Otto says:

    Marlie: Look for wscript.exe on your computer, in your Windows folder. Associate the files with that.

  • Marlie says:

    I am trying to run these scripts on Vista, but when I try to run a *.js file it just opens in Dreamweaver. I tried to associate it with something else, but I can’t find the program to use. Any suggestions?

  • username9876 says:

    Otto:

    One of the things that several other programs (like Winamp and MediaMonkey) offer is the ability to transcode files as they are transferred to an iPod. As far as I know, iTunes won’t do this. However, I understand that Doug Adams has a Lossless to AAC Workflow applescript (http://dougscripts.com/itunes/.....ccworkflow) that does just that. Would it be possible to create a similar script for Windows? If so, this would appear to solve a major issue for a lot of folks who want to keep Apple Lossless files on the PC and AAC files on the iPod. I know very little about scripting and was hoping that you would know if this is possible. Thanks in advance.

  • [...] chimpoid wrote an interesting post today onHere’s a quick excerpt [...]

  • jabp891 says:

    confused…

    Can this get you your music from your ipod, back on to the computer??

    If so, how do you do it??

  • PWAT says:

    Is it possible to have iTunes play a video file starting at a particular (user defined) play position (i.e., file location?), and maybe have it play for {x} number of seconds? Thanks.

  • Figment says:

    Hey, has anybody seen anything out there that will allow you to see what playlists a certain track may belong to? It would make managing my playlists much easier. Sometimes, I can’t remember if a song was included in a playlist and I will add it again, only to find later on that it was already there.

    If so, please email me the fix or code, or whatever, as it would be greatly appreciated.

  • fran says:

    Hello do you have a script for double track for windows/// remover of double soungs///

  • Randy says:

    With the addition of iTunes Store hi-quality artwork and coverflow in iTunes 7, I would love to see a script to go through your iTunes library looking for tracks that are using downloaded artwork in an ITC file, extract that artwork and embed the image in the music file itself.

    Thanks
    Randy

  • Otto says:

    Bettie:

    var iTunesApp = WScript.CreateObject("iTunes.Application");
    var track = iTunesApp.CurrentTrack;
    track.PlayedCount = 5;

    Just select your track in iTunes (highlight it) then run this script. It’ll set that tracks played count to 5.

  • Bettie says:

    I desperately need a way to manually change the playcounts on my songs.
    Any help would be greatly appreciated.

  • Otto says:

    Change the line that reads:
    if ( currTrack.Artwork.Count == 0 )

    To this:
    if ( currTrack.Artwork.Count != 0 )

    And you can also rename the playlist, if you like.

  • Torben says:

    How do I make one that gives me an ArtPlaylist just like the NoArtPlaylist but only for the files WITH album art? :D

    Thanks

  • Otto says:

    Curtis: The EvilLyrics script doesn’t magically go and get the lyrics for you. EvilLyrics does that when you play the songs. The script I wrote just looks for the resulting text files and loads them into iTunes as best it can.

  • Curtis says:

    I run it the .js file, but i dont think its working right. I have both Evillyrics and iTunes open, but nothing playing.
    It only updates 2 songs. Do I need to make a special playlist to have it update all (I changed the variable updateall to true)

    Thanks in advance.

  • Victor Feight says:

    Hello Otto,
    I just wanted to know if there was any modification in code that could be used in ClearLyrics or EvilLyricsImport that would be able to delete/import lyrics directly to my iPod instead of my iTunes library.
    Thank you,
    Victor

  • SteveG says:

    Hello Otto,
    I have been searching for a command-line script to insert a new playlist into iTunes. I could then add tracks to the new playlist using a script that I found on MetaFilter called AddToPlayList.js, which works great.

    Any ideas for adding a playlist?
    Thanks,
    Steve

  • John Mahoney says:

    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

  • John Mahoney says:

    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

  • John Mahoney says:

    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

  • Otto says:

    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.

  • John Mahoney says:

    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?

  • Campbell says:

    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

  • [...] info from one of the albums. -sort by whether album artwork is present or not. Fix: Otto’s iTunes javascript. -sort by whether lyric tag is present (contains lyrics) or not. Fix: Playlist script -integrated [...]

  • [...] also has other javascripts that actually helped me make my own. I had to search for official iTunes class namings to figure [...]

  • Pablo Rodriguez says:

    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.

  • nLoomis says:

    Great scripst Otto!, im just entering to the world of iPod and iTunes, and your scripts are the best i have found so far.

  • Maarten says:

    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…

  • Otto says:

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

  • Scavenger says:

    Hmm..trying RemoveDeadTracks and getting a
    “Library not registered” error?

  • eve says:

    the no-artwork script was perfect – thank you so much!

  • Discrepancy says:

    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.

  • Discrepancy says:

    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.”);

  • Judith says:

    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!

  • Otto says:

    pio: Reinstall iTunes. That means that it’s not registered properly, and needs to be installed correctly.

  • pio says:

    http://img176.imageshack.us/im.....rorgt5.png

    I’m getting this error, can someone help?!?!?!

  • conan troutman says:

    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

  • Pat says:

    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?

  • [...] iTunes Javascripts Nothing to see here (tags: itunes windows wscript list) [...]

  • Christian says:

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

  • Christian says:

    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

  • Carlos says:

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

  • Paul says:

    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?

  • michael says:

    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?

  • Peter says:

    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!

  • Jon says:

    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.

  • Otto says:

    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.

  • RC says:

    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.

  • GBugg says:

    THANK YOU!
    removedeadtracks.js has SAVED me!!

    Thank you VERY much for making this available!!!

  • John says:

    Looking for the same this as Sean above – changing the Play Count in Windows… help much appreciated!

  • Stefan says:

    Great job, scripts work perfectly well and were exactly what i’ve been looking for! Thanks a lot!!

  • Sean says:

    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!

  • Chris says:

    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!

  • rich says:

    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?

  • Chuck says:

    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.

  • [...] That should be all. You now have your iTunes alarm clock! You can, of course, do lots of other stuff. For example – if you have a program that translates any hot key to a command, you can make scripts for going to next and previous track, play/pause and similar. To get some good ideas, check this Microsoft article out. There is also some info here. Finally, do you have an idea for a script that none of these articles seem to describe? Download the Apple SDK, open the zip file and then open the iTunesCOMInterface.h file. Don’t be scared by all the C code – just search through it (for example, you want to activate Repeat, search for “repeat”). The name of the methods in the C code are most of the time identical to, or similar to, the commands you need to write in your script. Good luck! Tags:apple, code, howto, iTunes, programming, script, Technology windowsShare This [ ] [ January 17, 2007 ] [ Technology ] [ ] [...]

  • Seena says:

    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

  • Seena says:

    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

  • Otto says:

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

  • Lynn says:

    :( … But when I double click it, it just opens in notepad. Nothing else happens.

  • Otto says:

    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.

  • Lynn says:

    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.

  • Otto says:

    Ahh. Corrected.

  • RH says:

    Hey Otto,
    Figured it out. Your links point to http://ottodestruct.com/itunes/...
    It should be http://ottodestruct.com/iTunes/...
    The T needs to be capitalized.

    Thanks for the great code.
    RH

  • RH says:

    Hey Otto
    I can’t get any of the links to work.

    Thanks,
    RH

  • Otto says:

    The links should be working now.

  • QW says:

    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