Skip to content

Instantly share code, notes, and snippets.

@Pe8er
Created August 31, 2014 19:27
Show Gist options
  • Save Pe8er/9778af4394e358bb6e15 to your computer and use it in GitHub Desktop.
Save Pe8er/9778af4394e358bb6e15 to your computer and use it in GitHub Desktop.
global aname, tname, alname, stardisplay, rate
property blackStar : «data utxt2605» as Unicode text
property whiteStar : «data utxt2606» as Unicode text
set musicapp to my appCheck()
try
if musicapp is not false then
if musicapp is "iTunes" then
tell application "iTunes"
set {tname, aname, alname, rate, tduration} to {name, artist, album, rating, duration} of current track
set tpos to player position
end tell
else if musicapp is "Swinsian" then
tell application "Swinsian"
set {tname, aname, alname, rate, tduration} to {name, artist, album, rating, 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, rate} to {name, artist, album, popularity} of current track
set {tduration, tpos} to {"NA", "NA"}
end if
set stardisplay to my rating(rate)
return aname & " ~ " & tname & " ~ " & alname & " ~ " & stardisplay & " ~ " & tduration & " ~ " & tpos
else
return "Nothing playing" & " ~ " & "" & " ~ " & "" & " ~ " & "" & " ~ " & "" & " ~ " & ""
end if
on error e
return "Something went wrong…" & " ~ " & e & " ~ " & "" & " ~ " & "" & " ~ " & "" & " ~ " & ""
end try
on appCheck()
set apps to {"iTunes", "Spotify", "Swinsian"}
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
on rating(rate)
set stars to (rate div 20)
if rate is greater than 0 and stars is equal to 0 then
set stars to 1
end if
set stardisplay to "" as Unicode text
repeat with i from 1 to stars
set stardisplay to stardisplay & blackStar
end repeat
repeat with i from stars to 4
set stardisplay to stardisplay & whiteStar
end repeat
return stardisplay
end rating
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment