Fast script to duplicate an iTunes playlist?

Hi,

First, thanks a lot to the community here. It’s been a very helpful resource for AppleScript questions.

I’m trying to simply duplicate an iTunes playlist but my scripts are taking waaay too much time to complete.

Something as simple as this runs for a minute:


tell application "iTunes"
	duplicate every track of playlist "playlist1" to playlist "playlist2"
end tell

Do you know if there’s an alternative that runs faster than this?

Extra context:
My source playlist has 20,000 tracks, that sit on a separate “server” machine. All are indexed though.

Using iTunes’ UI, if I select them all then right click > “add to playlist […]” then that too takes ages. However, if I select the tracks then go to “File”>“New”>“Playlist from Selection”, that’s instantaneous. :expressionless: And why wouldn’t it? I’m not asking iTunes to duplicate the actual files, just the track references.

And btw, I’ve simplified the code to go to the essence of the issue, but my actual objective is to not just copy all tracks, but only the ones that match a criterion.
I.e this:


tell application "iTunes"
	duplicate (every track of playlist "playlist1" whose bpm is greater than 120 and bpm is less than 150) to playlist "playlist2"
end tell

From my testing it is clear that it is not the “bpm” condition that slows everything down, it’s the actual duplicate function.

Appreciate any help! This is the last problem I need to solve to bring to its conclusion a very cool project I’ve spent a couple of weeks on: generate playlists on the fly based on “mood” scores (happy, sad, danceable, bright timbre etc.), calculated in real time based on the inputs from a physical midi controller.

Model: MacBook Air
AppleScript: 2.5
Browser: Safari 537.36
Operating System: Mac OS X (10.12.6 beta 6)

If you run the script in Script Editor you will likely see some slowness. Because AppleScript. However, if you run it as a script from the iTunes Script menu it should run pretty speedily.

Hi Doug. I tried just now to run the same line of code mentioned above, from iTunes and from the script editor, and it takes the same time (around 26 secs) to find and “duplicate” 4000 tracks. :cry:

Would you know of another approach worth trying? I’m open to a mac gyver-style solution, as long as it results in a playlist that’s been filtered based on the bpm value. And it needs to be AppleScript, because I am using MidiPipe to trigger parts of the script’s code based on Midi control events.