Skip to content

Instantly share code, notes, and snippets.

@capnslipp
Last active December 29, 2022 17:30
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save capnslipp/5052157 to your computer and use it in GitHub Desktop.
Save capnslipp/5052157 to your computer and use it in GitHub Desktop.
Pause Spotify after the current song finishes playing
(*
@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