How do I search for every song match certain criteria? E.g., something like:
tell application "iTunes"
set tracks to (every file track of playlist "Library" whose name contains "Green")
repeat with t in tracks
display dialog (t as string)
end repeat
end tell
Just like that, except for two things; first,
tracksis a reserved word in the iTunes scripting dictionary, so replace it with something else (e.g.ts); second, you can’t just convert a track to a string witht as string; you have to choose what information you want. For instance, if you want the name, you can usename of t as string; if you want more detail, you could doname of t & " - " & artist of t; etc. Note also that if you want a more complicated predicate, you can just tack it on to thewhoseclause; for instance,file tracks whose name contains "Green" and artist contains "Bird".If you want to golf the script a little, you could replace it with the following:
Removing the
of playlist "Library"might produce slightly different results, but probably not. It didn’t in my quick testing.