For any given track in my iTunes library, I can easily ask for the physical location of the file like this,
tell application "iTunes"
set ilib to library playlist named "Library"
set z to (get first track in ilib)
get location of z
end tell
But I want to do the reverse. If I know the physical location of the file, I'd like to get to the track in the Library, if it has been added. I tried it like this
set x to (choose file)
tell application "iTunes"
set ilib to library playlist named "Library"
set y to (get track in ilib whose location is x)
end tell
but it fails...
error "iTunes got an error: Can’t get track of library playlist
id 6085 of source id 77 whose location = alias \"OS X
Partition:Users:...:somefile.m4a\"." number -1728 from track of
library playlist id 6085 of source id 77 whose location = alias
"OS X Partition:Users:...:file.m4a"
Any ideas how I can search the location property without resorting to some nasty loop?
EDIT:
Well, the good news is that my old macbook can loop through 2100 tracks in about 5 secs, so it is not so bad... :)