Delete Library Entries with Lost (Dead) Tracks (Mac OS X Only!)

Sometimes iTunes library displays tracks with an exclamation point next to it. They cannot be played, and if you try iTunes is asking to locate them.

But if you deleted them on purpose (or even inadvertently) and you know they are not there, you can delete them form the library, no problem: there are no music files associated to them.

This issue can be more annoying if you deleted a bunch of tracks because you will have to go and delete all corresponding entries. The problem is that it is hard to find all tracks that have been deleted especially if you access the library through a third party app (for saving storage space for example, or if you use a music deejaying application). 

As some of us have been experiencing this, we wanted to share this tip: 

  • Open your Mac's Library Folder (at the root of the Finder, do not go to your own [User] Library Folder)
  • Open the Library folder 
  • Open the iTunes folder
  • Look for a folder called Scripts - if you don't have it, create it  (you will need your admin password)
  • Open the Apple Script Editor (in Utilities) 
  • Copy and paste the script below and save the script to the "Scripts" folder (Library>iTunes>Scripts)
  • Quit and reopen iTunes, in the top menu you will see a script icon, you can launch your super Remove Dead Tracks Script!

Super Remove Dead Tracks Script:

(*
"Super Remove Dead Tracks" for iTunes
written by Doug Adams
[email protected]

v1.5 october 26 2005
-- prevents error when trying to delete empty Smart Playlists and/or playlist that can't be deleted (Party Shuffle, Podcasts, etc)
-- code tweaks

v1.0 sep 25 2003
-- initial release

Get more free AppleScripts and info on writing your own
at Doug's AppleScripts for iTunes
http://www.dougscripts.com/itunes/

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

Get a copy of the GNU General Public License by writing to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.

or visit http://www.gnu.org/copyleft/gpl.html

*)

-------------------------------------
(* the number below is the number of tracks
to count before reporting progress -
you can change this number to a larger or smaller number.

If you set it to zero, you will not see the progress message *)

property progress_factor : 500

tell application "iTunes"
display dialog "Super Remove Dead Tracks" & return & return & ¬
"Removes tracks whose files are missing or deleted, so-called" & ¬
"\"dead\" tracks designated with (!) next to the track name." buttons ¬
{"Cancel", "Proceed..."} default button 2

set mainLibrary to library playlist 1
set totalTracks to count of file tracks of mainLibrary
set all_playlists to user playlists whose smart is false -- don't delete Smart Playlists later

set deleted_tracks to 0
set all_checked_tracks to 0
set countem to ""

set oldfi to fixed indexing
set fixed indexing to true

repeat with t from totalTracks to 1 by -1

try
set this_track to file track t of mainLibrary

if this_track's location is missing value then
delete this_track
set deleted_tracks to deleted_tracks + 1
end if

set all_checked_tracks to all_checked_tracks + 1

if frontmost then
if (progress_factor is not 0) and (all_checked_tracks mod progress_factor) is 0 then
if deleted_tracks is greater than 0 then ¬
set countem to (deleted_tracks & " dead tracks removed so far...")
if frontmost is true then display dialog (all_checked_tracks as string) & ¬
" tracks checked..." & ¬
return & countem buttons {"Cancel", «data utxt266B»} giving up after 1
end if
end if
end try

end repeat

set fixed indexing to oldfi

repeat with this_playlist in all_playlists
if (get count of tracks of this_playlist) is 0 then
try
delete playlist this_playlist
end try
end if
end repeat

if deleted_tracks is greater than 0 then
set ps to " was"
if deleted_tracks is not 1 then set ps to "s were"
display dialog "Finished removing \"dead\" tracks." & return & ¬
deleted_tracks & " track" & ps & ¬
" removed." buttons {"Thanks"} default button 1 with icon 1
else
if gave up of (display dialog "It was not necessary to remove any tracks." buttons {"Thanks"} ¬
default button 1 with icon 1 giving up after 15) is true then error number -128
end if

end tell

The script is called Super Remove Dead Tracks v3.2, it's available here and discussed (and well explained too) in this very forum thread where DJ's share tech tips.

Have more questions? Submit a request

Comments

  • Avatar
    Victoria Gartman

    Wow, it took about 5 seconds to remove the dead tracks.  The information totally rocks.

Powered by Zendesk