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.");
}

21 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

  12. Pepper says:

    After 2 years of looking how to remove them, I had almost given up. This is great! Thanks infinitely!

  13. Tradsud says:

    Thanks, script still works great. I ran it from an administrative command prompt, at first it didn’t look like it was running, but it was, and worked great.

  14. KatharosSkotos says:

    Much thanks! <3 I'm relocating all of my music files into one Folder, instead of all over the place like it currently is. With 18k songs, going through and ridding the '!' would have gotten quite annoying. x_x

  15. jhirschel says:

    thanks so much. i was ready to curse my command prompt.

  16. nproc says:

    OMG, this is the most amazing thing!!!!!!!!!!!! I was sitting down every day & deleting a little at a time!! I got a new hard drive & when I moved everything over EVERYTHING was duplicated, giving me 12,000+ songs. Hallelujah, thanks a million. :)

  17. Lucky Rucksack says:

    One question: Each time I run this do I need to type RemoveDeadTracks.js in the command line?

    Or is there some button-ish thingy I can put somewhere (preferably in itunes)

    That would be neat.

    Or maybe i am just horribly, horribly stoned.

  18. Thanks! That was EASY and FAST and worked perfectly.

  19. JLO says:

    thank you very much … this work as advertised and even better :)

  20. Nemo says:

    Thank you body, you saved me, i just renamed a 100Giga file… Hell, it was a mess! XD

  21. Fred - San Antonio says:

    I just ran it today 5/5/2012 on iTunes 10.6.1.7. It worked like a charm. Thanks for taking the time to share the code – and if you are the author, a special thanks. Should be a standard command in iTunes provided by Apple.

Leave a Reply