get track by filename in itunes

hi,

how can I find all tracks in a playlist whose name contain a given string?

The following does not work because location is an alias.

set mytracks to tracks of playlist "Music" whose location contains "somestring"

I did a loop to get the POSIX path of the locations of all tracks and compare them to mystring, but I’d like to know if it can be done directly with something similar to the script shown above.

thanks

jul

tell application "iTunes"
	set mytracks to tracks of playlist "some list" whose name contains "some string"
end tell

Sorry, I meant “all tracks in a playlist whose FILE name contain a given string”

Any idea?

This is a bit clunky, but it works:

tell application "iTunes"
	set blue_List to make new playlist with properties {name:"Blue Tracks"}
	set bsa_tracks to {database ID, location} of every track of playlist "BSA517"
	repeat with x from 1 to (length of item 1 of bsa_tracks)
		if (((bsa_tracks's item 2)'s item x) as string) contains "blue" then
			duplicate (every track of first library playlist whose database ID is (item x of item 1 of bsa_tracks)) to blue_List
		end if
	end repeat
end tell

First, it creates a playlist to put everything that fits the search. Then it creates a list of two lists, one with the database ID of every track in a specific playlist, then a list of the location aliases of those tracks. It then loops through the list of aliases, converts each to a string value, and checks to see if a certain string is in there or not. If so, it uses the corresponding database ID to put the track into the freshly created list.

Keep in mind that the location is complete; it is the entire path to the file, not just the filename. If any of the strings in path contain the search string, it will return true.