Just like that, except for two things; first, tracks
is 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 with t as string
; you have to choose what information you want. For instance, if you want the name, you can use name of t as string
; if you want more detail, you could do name of t & " - " & artist of t
; etc. Note also that if you want a more complicated predicate, you can just tack it on to the whose
clause; 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:
tell application "iTunes"
repeat with t in (file tracks whose name contains "Green")
display dialog (name of t as string)
end repeat
end tell
Removing the of playlist "Library"
might produce slightly different results, but probably not. It didn't in my quick testing.