Skip to content

Instantly share code, notes, and snippets.

@jlengrand
Created April 22, 2018 17:45
Show Gist options
  • Save jlengrand/ec2fff0f741ae0a59a7f203d9ffee348 to your computer and use it in GitHub Desktop.
Save jlengrand/ec2fff0f741ae0a59a7f203d9ffee348 to your computer and use it in GitHub Desktop.
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