Skip to content

Instantly share code, notes, and snippets.

@BrettBukowski
Created September 7, 2014 14:24
Show Gist options
  • Save BrettBukowski/7585bc6bc83bb66dabc7 to your computer and use it in GitHub Desktop.
Save BrettBukowski/7585bc6bc83bb66dabc7 to your computer and use it in GitHub Desktop.
Gets the currently-playing track info
global aname, tname, alname
set musicapp to my appCheck()
try
if musicapp is not false then
if musicapp is "iTunes" then
tell application "iTunes"
set {tname, aname, alname, tduration} to {name, artist, album, duration} of current track
set tpos to player position
end tell
else if musicapp is "Spotify" then
tell application "Spotify" to set {tname, aname, alname} to {name, artist, album} of current track
set {tduration, tpos} to {"NA", "NA"}
else if musicapp is "Vox" then
tell application "VOX" to set {tname, aname, alname, tduration, tpos} to {track, artist, album, total time, current time} of application
end if
return aname & " |~| " & tname & " |~| " & alname & " |~| " & tduration & " |~| " & tpos
else
return ""
end if
on error e
return ""
end try
on appCheck()
set apps to {"iTunes", "Spotify", "Vox"}
set playerstate to {}
repeat with i in apps
tell application "System Events" to set state to (name of processes) contains i
if state is true then
using terms from application "iTunes"
tell application i to if player state is playing then set playerstate to playerstate & i
end using terms from
end if
end repeat
if (count of items in playerstate) is 1 then
return playerstate as text
else
return false
end if
end appCheck
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment