Spotify repeat and shuffle woes

For some reason shuffle and repeat functions of spotify don't work with btt anymore, even if sent to app, other functions work.

Applescript works to control it but I would need a more sophisticated script to enable a toggle

tell application "Spotify"
set repeating to true
end tell

works but only from an off state to basic on state, not toggling through, same for shuffle,

much thanks appreciated, chatgpt didn't help ;/

You do actually want to use Keyboard Maestro for these tasks? You mention BTT but maybe meant KM?

You could try the Select or Show a Menu Item action to start with, since both Shuffle and Repeat are in Spotify's menu.

1 Like

tried with btt and spoke to the dev, he tried to help but something in btt doesn't work without bringing up an annoying flicker of the app to foreground because spotify changed something only for repeat and shuff, so I figure maybe km could do it. I'll play with the action thanks.

seemed to work but also flickers as it brings up spotify briefly when outside the spotify app, wish it would work in background somehow, but flicker is less obstrusive via km than btt at least.

These work for me to toggle the states of shuffle and repeat. You could put them in Keyboard Maestro Macros using Execute an AppleScript Actions.

tell application "Spotify"
  if repeating is false then
    set repeating to true
    set repeating to false
  end if
end tell
tell application "Spotify"
  if shuffling is false then
    set shuffling to true
    set shuffling to false
  end if
end tell
1 Like

Hi Zabobon, I was given the same advice on btt forum, that solves the shuffling toggle, but strangely it seems spotify went from off, on, one for repeat to true or false, so it toggles repeat on or off.

I'm often distracted doing other things and like to have my songs on repeat one, or repeat the track until I switch tracks or stop, this seems to not be in the applescript dictionary anymore, and spotify stupidly takes off repeat one to track repeat when you change tracks

So it seems bringing it to the foreground might be the only way, outside python coding and spotipy which I don't understand.

so I might have to get used to a millisecond flicker when it brings it up :yum:

but thank you for your help.

Since those functions have key shortcuts, you can use Type a Keystroke with the send to background app option.

All I could find is this, and this doesn't send to spotify when it's in background, only works when player is running,

I just tried it, and sending Cmd-R worked, but after I tried sending Cmd-S in the same way, which failed, sending Cmd-R became unreliable. Oh dear!

So yes, it seems that Spotify is an awkward target for both BTT and KM now.

A healthy opportunity to blink.

According to Bing Chat:

You can use the Spotify API to cycle through the three repeat modes in the desktop app on Mac. The Spotify API provides an endpoint for setting the repeat mode of the player. You can use a PUT request to the /v1/me/player/repeat endpoint with an OAuth token authorized with the user-modify-playback-state scope. The state parameter in the request body can be set to track, context, or off to cycle through the repeat modes.

Here is an example of a curl command that sets the repeat mode to context:

curl -X "PUT" "" -H "Accept: application/json" -H "Content-Type: application/json" -H "Authorization: Bearer {your access token}"

You can use this command in a script or program to cycle through the repeat modes.

To get access to the Spotify API, you need to follow these steps:

  • Create a Spotify account: If you don’t already have one, create a Spotify user account (Premium or Free) by signing up at
  • Log into the Spotify Developer Dashboard: Go to the Dashboard page at the Spotify Developer website and log in using your Spotify account.
  • Create an app: Once you have logged into the dashboard, create an app. This will give you access to the app credentials, which are required for API authorization to obtain an access token.
  • Obtain an access token: Use the app credentials to obtain an access token. This token is used in your API requests to authenticate and authorize your app.

Once you have completed these steps, you can use the curl command I provided earlier to set the repeat mode of the player using the Spotify API.
You will need to replace {your access token} in the command with your actual access token.

1 Like

thanks, I had somebody make some complex scripts for me before in python, I do have an app and got an access token and put it in your script and it said 403 error premium required, but I have premium so I think this pretty much above my head, but maybe one day I'll figure it out.