Played Date in iTunes

I’m trying to tell iTunes to delete all TV shows that have been played more than 30 days ago.

tell application “iTunes”
set TheTracks to location of (file tracks whose (video kind is TV show) and (unplayed is false) and (((played date) + (30 * days)) is greater than (current date)))
end tell

It works without the played date but with played date applescript complains it can’t get date. How am I using it wrong?

It’s the ‘+ (30 * days)’ that’s causing the problem. You can’t do additions in the middle of a ‘whose’ filter. (And if you could, your filter would return shows that were last played less than 30 days ago!) You should subtract 30 days from the current date and look for played dates which are less than (or ‘come before’) that.

set cutoffDate to (current date) - 30 * days
-- set cutoffDate's time to 0

tell application "iTunes"
	set TheTracks to location of (file tracks whose (video kind is TV show) and (unplayed is false) and (played date comes before cutoffDate))
end tell

‘(current date) - 30 * days’ is 30 * 24 hours before the time of the current date, so the cutoff point will be some time during the day 30 days ago. If you want to exclude that day altogether, set the cutoff time to midnight by uncommenting the second line.

I can’t actually test the script, but I think the suggested modification should work.

This did work. This will help me with other scripts as well. Thank you very much