Buffering the contents of Smart Playlists

I have tracked an intermittent error down in one of my iTunes scripts to the fact that tracks I’m modifying no longer match the source smart playlist criteria so the object reference (I apologize if my terminology is incorrect) becomes invalid. The slow access time of the SD card where the data is stored gives the smart playlist time to update (before when I used an external hard drive it did not). This behavior wasn’t what I was expecting so it took me a while to figure out, and then only by experiment: copying all the tracks from the smart playlist to a “dumb” one and then performing my track modifications on a list derived from that made the occasional error disappear. I’ve looked for a more elegant solution, but my search attempts have been unsuccessful.

Here are my ideas for possible methods of improvement, limited by my ignorance. Further suggestions are most welcome:

  1. Create an Applescript list of objects in a way that the object references don’t become invalid if the smart playlist changes. Maybe there’s a standard way to do this? I had naively assumed it’d work this way by default.

  2. Programmatically toggle “live updating” off for the smart playlist and then back on again after I’m done. The iTunes dictionary doesn’t show anything about this so I am not hopeful.

  3. Stick with copying the tracks to a “dumb” playlist before messing with them, but optimize how it is done.

Thank you very much for any suggestions.

Try something like this:

tell application "iTunes"
	set l to persistent ID of every track of playlist "90's Music" of source "Library"
	set x to item 2 of result
	set t to some track of library playlist 1 of source "Library" whose persistent ID is x
	
	tell t
		name
	end tell
end tell

Hope it helps.

That’s the sort of thing I was hoping for! I’ll give it a shot. Thanks!

Seems to have done the trick. Thanks again.

:slight_smile: