This is an applescript that should work for your situation:
- Code: Select all
set removeTotal to 0
tell application "iTunes"
set mainLibrary to library playlist 1
set totalTracks to count of file tracks of mainLibrary
with timeout of 10 seconds
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 and this_track's duration is missing value then
removeTotal = removeTotal + 1
delete this_track
end if
end try
end repeat
end timeout
end tell
Essentially, this script checks for anything in the iTunes library (books, music, movies, etc.) whose
duration element is null. Even for books, the duration element returns a zero value if the file is present.
Notice the removeTotal variable is currently not used. You could export this as a token to Hazel in order to send an alert that "19 items have been removed from the iTunes library."
Hope this helps!
EDIT - To clarify, this will remove a file from the iTunes library database only. You should physically delete the file from the iTunes directories before this script is run.