Skip to content

Instantly share code, notes, and snippets.

@gmanley
Last active February 16, 2021 03:22
Show Gist options
  • Save gmanley/750426aa91097aeef3aee5a73a1f5a04 to your computer and use it in GitHub Desktop.
Save gmanley/750426aa91097aeef3aee5a73a1f5a04 to your computer and use it in GitHub Desktop.
(function() {
var currentApp = Application.currentApplication()
currentApp.includeStandardAdditions = true
if (currentApp.systemInfo().systemVersion >= "10.15") {
var musicApp = Application("Music")
} else {
var musicApp = Application("iTunes")
}
var markTrack = (track, shouldLove) => {
if (shouldLove) {
track.loved = shouldLove
return "Loved: " + track.name()
} else {
track.loved = shouldLove
return "Unloved: " + track.name()
}
}
var shouldLove = "{query}" == "true"
if (currentApp.name == musicApp.name) {
var selection = musicApp.selection()
if (selection.length > 0) {
selection.forEach(track => {
markTrack(track, shouldLove)
})
return "Loved: " + selection.map(t => t.name()).join(" & ")
} else {
return markTrack(musicApp.currentTrack(), shouldLove)
}
} else {
return markTrack(musicApp.currentTrack(), shouldLove)
}
})()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment