Unknown Object Type

In the code below

tell application "iTunes"
	repeat with t in (tracks of playlist "Podcasts" where ((unplayed is false) and (played count is not 0) and (enabled is true)))
		try
			set (enabled of t) to false
		on error number -1731
			-- ignore
		end try
	end repeat
end tell

If I do not have the try, sometimes I get “Unknown Object Type” and the set statement is highlighted. If I put the try, the repeat does not finish the loop – it unsets only one track.

Any ideas of why I’m getting the error in the first place?

Browser: Firefox 3.0.11
Operating System: Mac OS X (10.5)

I just so totally hate Applescript … but I’ll behave myself.

This works:

tell application "iTunes"
	set trcks to (every track of playlist "Podcasts" whose enabled is true and unplayed is false and played count is not 0)
	repeat with t in trcks
		-- display dialog "a '" & (class of t) & "'"
		set (enabled of t) to false
	end repeat
end tell

This does not:

tell application "iTunes"
	repeat with t in (every track of playlist "Podcasts" whose enabled is true and unplayed is false and played count is not 0)
		-- display dialog "a '" & (class of t) & "'"
		set (enabled of t) to false
	end repeat
end tell

In the second script, t is sometimes set to an application object. Go figure.

Anyhow, this could be useful to others. If you manage your iPod to include only checked items and you don’t want podcasts that you have listened to, this script quickly runs through and unchecks the postcasts that ave checked, have been played, and play count is not 0. The last two conditions seem overly specified but I think (pasted on past experience) both are needed.

You might also want to add in the skipped count if that is accessable. I’m not sure if it is. That way if you start listening to a podcast, decide you don’t want to listen to it, you don’t have to jack around getting the play count to 1.

Well, ignore that. I can’t get the “Skipped count” to be anything except 0 for a podcasts.

I’m going home…

this will work, too


tell application "iTunes"
	repeat with t in (get tracks of playlist "Podcasts" where ((unplayed is false) and (played count is not 0) and (enabled is true)))
		set (enabled of t) to false
	end repeat
end tell

notice the get statement

the problem is, the index variable t is generated once, but the amount of tracks is decreased in each iteration of fetching the tracks.
The extra line or the keyword get (which retrieves the tracks also once) avoids the problem