import "@johnlindquist/kit"
let appsToTry = [
"Music",
"Spotify"
]
let qs: string
for (let app of appsToTry) {
qs = await applescript( `
tell application "${app}"
if player state is playing then
set aTrack to the current track
set aName to name of aTrack
set aArtist to artist of aTrack
return quoted form of (aArtist & " - " & aName)
else
return ""
end if
end tell
`)
if (qs) break
}
if (!qs) {
notify(`No music is playing in: ` + appsToTry.join(", "))
} else {
open(`http://genius.com/search?q=${qs}`)
}