Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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