Skip to content

Instantly share code, notes, and snippets.

@dnicolson
Last active November 10, 2018 17:39
Show Gist options
  • Save dnicolson/685869ad1ea4740c1cc0dc8eea85584c to your computer and use it in GitHub Desktop.
Save dnicolson/685869ad1ea4740c1cc0dc8eea85584c to your computer and use it in GitHub Desktop.
JXA to add songs to a playlist based on an artist and list of songs
const ARTIST = ''
let TRACKS = []
const app = Application('iTunes')
const destinationPlaylist = app.userPlaylists.whose({name: {_equals: ARTIST}})[0]
TRACKS.forEach((name) => {
const matchedNames = app.playlists.whose({name: 'Library'})[0].tracks
.whose({name: {_equals: name}})
for (let i = 0; i < matchedNames.length; i++) {
if (matchedNames[i].artist() === ARTIST) {
matchedNames[i].duplicate({to: destinationPlaylist})
TRACKS = TRACKS.filter(n => n !== name)
}
}
})
TRACKS
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment