I'm trying to build a simple JavaScript for Automation script to add the currently playing track in iTunes to a particular playlist.
I have the playlist name stored as a string, var playlist
.
The JXA Library add method says the following:
add method : add one or more files to a playlist
add list of file : the file(s) to add
[to: location specifier] : the location of the added file(s)
→ Track : reference to added track(s)
What I can't figure out is what to put for the [to: location specifier]
part to specify a playlist.
I tried:
playlist = 'Queue'
iTunes = Application('iTunes')
iTunes.add(iTunes.currentTrack, {to: iTunes.playlists[playlist]})
But I get "Error -1708: Message not understood."
add
doesn't do what you want here (add
is used primarily for importing files outside of iTunes into the application, that's what the location specifier refers to).
You want to use the duplicate
method on the track you want to "duplicate", copying it "to" the destination playlist. This code snippet works for me:
var iTunes = Application('iTunes');
var playlist = iTunes.playlists['Queue'];
iTunes.currentTrack().duplicate({to:playlist});