-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Applescript for Spotify button within BetterTouchTools
- Loading branch information
Showing
1 changed file
with
31 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |