MacOS – Show only imported files in iTunes

itunesmacos

I'm new to iTunes and I don't like that it lists all files ever played in the categories "Songs" or "Albums" for example. I only have a few albums on my mac, but I have listened to a lot of stuff, mostly from external drives.

My problem:
Saying I want to listen to some music, it's pretty hard to find the music which is actually playable, because iTunes shows all files ever played. Is it possible to show only files which I have actually imported, without turning on copy files to iTunes Media?

iTunes

Best Answer

You can delete items whose files have been removed by running this from AppleScript Editor:

tell application "iTunes"
    repeat 5 times
        repeat with t in file tracks of library playlist 1
            try
                if location of t is missing value then delete t
            end try
        end repeat
    end repeat
end tell

I don't know why you have to run it multiple times, but it usually removes all items after about five times.