Skip to content

Instantly share code, notes, and snippets.

@davidsharp
Created April 29, 2020 11:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save davidsharp/707417fdc85b3128f91bb075fb17fbcc to your computer and use it in GitHub Desktop.
Save davidsharp/707417fdc85b3128f91bb075fb17fbcc to your computer and use it in GitHub Desktop.
bitbar plugin that provides a shuffle button for Spotify
#!/bin/bash
function shuffle(){
osascript -l JavaScript<<'END'
const spotify = Application('spotify')
if(spotify.running()){
try{
spotify.shuffling = !spotify.shuffling()
}
catch(e){''}
}
else ''
END
}
if [[ "$1" = "shuffle" ]]; then
shuffle
fi
function shuffle_state(){
osascript -l JavaScript<<'END'
const spotify = Application('spotify')
if(spotify.running()){
try{
spotify.shuffling()?'🔀':'🔁'
}
catch(e){'💚'}
}
else ''
END
}
function run(){
state=$(shuffle_state)
if [[ $state ]];then
echo "$state|bash=$0 param1=shuffle terminal=false refresh=true"
fi
}
dir=$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )
run
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment