Last active
January 28, 2025 22:51
-
-
Save capnslipp/5052157 to your computer and use it in GitHub Desktop.
Pause Spotify after the current song finishes playing
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
(* | |
@author: Slipp Douglas Thompson | |
@purpose: Pauses Spotify after the current song finishes playing. | |
@todo: Optimize so it's more efficient. | |
@usage: Drop a compiled script (a .scpt file, converted with AppleScript Editor if this is a .applescript file) into ~/Library/Scripts/Applications/Spotify. | |
Ensure than “Show Script menu in menu bar” is enabled (which can be found in the AppleScript Editor preferences). | |
When playing a song in Spotify and wishing to stop the music when the track finished, choose “When Song Finishes, Pause” from the script menu, and then walk, walk away. | |
*) | |
tell application "Spotify" | |
log "“When Song Finishes, Pause”: player state is " & (player state) | |
if player state is playing then | |
-- keeping a reference of the current track object doesn't work with Spotify | |
-- (‘current track’ must be a single object that changes its properties) | |
-- so instead, we're using the id | |
set initialCurrentTrackId to (id of current track) | |
log "“When Song Finishes, Pause”: current track is " & (name of current track) | |
repeat until initialCurrentTrackId is not (id of current track) | |
-- wait | |
log "“When Song Finishes, Pause”: current track id is “" & (id of current track) & "”, initialCurrentTrackId is “" & initialCurrentTrackId & "”" | |
end repeat | |
log "“When Song Finishes, Pause”: issuing pause" | |
pause | |
end if | |
end tell |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment