Hey everyone, newish question here. I’m trying to write a script for iTunes that will take the user’s selected tracks and filter out those whose date fall after a certain year. Right now I’m starting smaller and trying to filter out track’s whose year is2007. The every whose clause seems appropriate here but I can’t get teh script to compile. Here is my code:
tell application "iTunes"
get selection -- Returns a list whos contents are type "File Track"
get file tracks of the result whose (year of it is equal to 2007) -- Tracks have a year property and this property holds an integer.
--Do Stuff Here to the resulting items
end tell
When I compile it says “Can’t get {} whose year = 2007”
the whose filter doesn’t work in almost all “custom” lists.
Use a repeat loop
tell application "iTunes"
set L to {}
repeat with i in (get selection)
if year of i is 2007 then set end of L to contents of i
end repeat
L
--Do Stuff Here to the resulting items
end tell
I haven’t tested this (and I don’t script iTunes) but usually when you say “it” in a script it refers back to the current tell block you are in. I believe you are telling it to look at the “year of iTunes”.
maybe:
get file tracks of the result whose year is equal to 2007
I don’t know iTunes but 2007 may need to be in quotes - “2007”.
Model: G5 OSX 10.4.8
Browser: Safari 419.3
Operating System: Mac OS X (10.4)
tell application "iTunes"
set test to file tracks of library playlist 1 whose year is equal to 2007
end tell
tell application "iTunes"
set test to every track of library playlist 1
-- test is now a list
set test to file tracks of test whose year is equal to 2007
end tell
I believe the common problem with selection is that it is a property of the application object (which happens to return a list).
Interesting. Thanks for clearing that up. i have one more question though. As I noted before I am writing a script to archive my podcasts. I have also read an every/whose clause is much faster than a repeat loop and should be used when ever possible. Is it better form to use whose clauses to filter out the tracks that are podcasts and fall within a certain date range? Or should I just get the selected tracks from iTunes and use repeat loops to filter out what I don’t want?