Skip to content

Commit

Permalink
Applescript for Spotify button within BetterTouchTools
Browse files Browse the repository at this point in the history
  • Loading branch information
dallinski committed Apr 8, 2021
1 parent 7342b95 commit f724f4d
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions MacOS/spotify_button.scpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
-- This script can be used in conjunction with Better Touch Tool to display the currently playing track on the MacBook Pro TouchBar
-- More info here: https://lucatnt.com/2017/02/display-the-currently-playing-track-in-itunesspotify-on-the-touch-bar

on FormatSeconds(totalSeconds)
set theMinutes to (totalSeconds div minutes)
set theRemainderSeconds to (totalSeconds mod minutes)

if length of (theRemainderSeconds as text) = 1 then
set theRemainderSeconds to "0" & (theRemainderSeconds as text)
end if

set theTimeString to theMinutes & ":" & theRemainderSeconds as text

return theTimeString
end FormatSeconds

on MillisToSeconds(millis)
return round ((millis / 1000)) rounding down
end MillisToSeconds

if application "Spotify" is running then
tell application "Spotify"
if player state is playing then
return (get artist of current track) & " - " & (get name of current track) & " (" & my FormatSeconds(get player position as integer) & "/" & my FormatSeconds(my MillisToSeconds(get duration of current track)) & ")"
else
return (get artist of current track) & " - " & (get name of current track) & ""
end if
end tell
else
return "Spotify"
end if

0 comments on commit f724f4d

Please sign in to comment.