RemoveDeadTracks.js


Article Image
Tags:

Added On: 5th Jan 08

Links: [download]

This script will run through your iTunes library and delete all those pesky little exclaimation marked “dead” tracks, which iTunes cannot find on your computer.

Sometimes another program will move the files, or iTunes will apparently just “forget” where they are! Running this download will remove all these unlinked tracks from the list.


var ITTrackKindFile = 1;
var iTunesApp = WScript.CreateObject("iTunes.Application");
var deletedTracks = 0;
var mainLibrary = iTunesApp.LibraryPlaylist;
var tracks = mainLibrary.Tracks;
var numTracks = tracks.Count;
var i;
while (numTracks != 0)
{
var currTrack = tracks.Item(numTracks);
// is this a file track?
if (currTrack.Kind == ITTrackKindFile)
{
// yes, does it have an empty location?
if (currTrack.Location == "")
{
// yes, delete it
currTrack.Delete();
deletedTracks++;
}
}
numTracks--;
}
if (deletedTracks > 0)
{
if (deletedTracks == 1)
{
WScript.Echo("Removed 1 dead track.");
}
else
{
WScript.Echo("Removed " + deletedTracks + " dead tracks.");
}
}
else
{
WScript.Echo("No dead tracks were found.");
}

11 Responses to “RemoveDeadTracks.js”

  1. CardinalJo says:

    Hello,

    Just a question, how do you run this script ?

    Thanks a lot !

  2. M says:

    Thanks a lot for all your great work!

  3. Henry says:

    Thanks, this works great. I setup a scheduled task to run this daily.

    @CardinalJo, To run this file, on your Windows machine, do the following:
    * Open iTunes.
    * Click Start | Run … | cmd) (this opens a command prompt)
    * Type notepad RemoveDeadTracks.js and then press Enter.
    * Click Yes when asked to create a new file.
    * Copy the above code into the text file and Save, then exit.
    * Back at the command prompt, type RemoveDeadTracks.js
    The script will run and then popup a message when done. It took me about 5 minutes to run, but it can easily take longer.

  4. Sim says:

    This worked great, thanks a lot!!!

  5. DASH says:

    How can you tell if the script is running? Seems to be taking forever…thanks

  6. Andy says:

    Hi can anyone please tell me what i have done wrong although I believe to have followed the directions I am having a windows cannot open this file popup! Anyone know where I have gone wrong? Thanks

  7. Alex says:

    Thanks so much for your JS file. Awesome tool. BTW, for those who want to just launch the JS file download, you need Windows Script running on your PC, which you can get here: http://www.microsoft.com/downloads/en/confirmation.aspx?familyId=c717d943-7e4b-4622-86eb-95a22b832caa&displayLang=en.

    Good luck.

  8. midas says:

    THANK YOU SO MUCH FOR THOSE INSTRUCTIONS.

    Bye Bye 1604 dead tracks. Life is good!

  9. Divdov says:

    Thank you for solving a problem that’s been REALLY annoying me.
    I have 13000 tracks to search and it’s taking ages. If you are not sure if anything is happening open the i-tunes library window and you should notice at the bottom of the screen the number of tracks gradually going down.
    Thanks again!

  10. Daniel says:

    Nice clean script, well written. Good job

  11. Beirti says:

    Thank you! Saved me hours of ctrl clicking

Leave a Reply