Advertisement
Guest User

Spotify - Get Track Info

a guest
Mar 17th, 2018
1,743
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. on ApplicationIsRunning(appName)
  2.     tell application "System Events" to set appNameIsRunning to exists (processes where name is appName)
  3.     return appNameIsRunning
  4. end ApplicationIsRunning
  5.  
  6. if ApplicationIsRunning("Spotify") then
  7.     tell application "Spotify"
  8.         set currentArtist to artist of current track as string
  9.         set currentTrack to name of current track as string
  10.         set totalLength to duration of current track as integer
  11.         set totalLengthInSeconds to totalLength / 1000 as integer
  12.         set playerPosition to player position as integer
  13.         set timeLeft to totalLengthInSeconds - playerPosition
  14.        
  15.         set minutes to timeLeft div 60 as integer
  16.         set secondsString to timeLeft mod 60 as string
  17.         if the length of secondsString is 1 then
  18.             set secondsString to "0" & secondsString as string
  19.         end if
  20.         set timeLeftMMSS to minutes & ":" & secondsString
  21.        
  22.         return currentArtist & " - " & currentTrack & " - " & timeLeftMMSS
  23.     end tell
  24.    
  25. else
  26.     return "Spotify"
  27. end if
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement