RemoveDeadTracks.js
Tags: Dead Tracks
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.");
}


Hello,
Just a question, how do you run this script ?
Thanks a lot !
Thanks a lot for all your great work!
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.
This worked great, thanks a lot!!!
How can you tell if the script is running? Seems to be taking forever…thanks
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
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.
THANK YOU SO MUCH FOR THOSE INSTRUCTIONS.
Bye Bye 1604 dead tracks. Life is good!
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!
Nice clean script, well written. Good job
Thank you! Saved me hours of ctrl clicking
After 2 years of looking how to remove them, I had almost given up. This is great! Thanks infinitely!
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.
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
thanks so much. i was ready to curse my command prompt.
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. :)
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.
Thanks! That was EASY and FAST and worked perfectly.
thank you very much … this work as advertised and even better :)
Thank you body, you saved me, i just renamed a 100Giga file… Hell, it was a mess! XD
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.