Instantly share code, notes, and snippets.

Embed
What would you like to do?
Activating / Deactivating Spotify proxy settings
#!/bin/sh
ON_OFF=$1
SPOTIFY_PREFS="$HOME/Library/Application Support/Spotify/prefs"
PROXY_ON="network.proxy.mode=2" #HTTP Proxy
PROXY_OFF="network.proxy.mode=1" #No proxy
if [ ! -f "$SPOTIFY_PREFS" ]; then
echo "Spotify preference file not found. Exiting"
exit 1
fi
if [ "$ON_OFF" = "on" ]
then
echo "Activating Spotify proxy settings"
sed -i -e "s/$PROXY_OFF/$PROXY_ON/g" "$SPOTIFY_PREFS"
elif [ "$ON_OFF" = "off" ]
then
echo "Deactivating Spotify proxy settings"
sed -i -e "s/$PROXY_ON/$PROXY_OFF/g" "$SPOTIFY_PREFS"
elif [ "$ON_OFF" = "show" ]
then
cat "$SPOTIFY_PREFS"
exit 1
else
echo "Invalid command entered. Please use 'spotiProxy on' or 'spotiProxy off'"
exit 1
fi
number_processes=$(pgrep Spotify | wc -l)
if [ $number_processes -gt 1 ]
then
echo "Restarting Spotify"
osascript -e 'quit app "Spotify"'
sleep 1
open -a Spotify
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment