Skip to content

Instantly share code, notes, and snippets.

@joerobot
Last active March 25, 2020 16:18
Show Gist options
  • Save joerobot/462aa995095bfccdfd5f511a3edfdfbe to your computer and use it in GitHub Desktop.
Save joerobot/462aa995095bfccdfd5f511a3edfdfbe to your computer and use it in GitHub Desktop.
Making Spotify HTTP Proxy Switching Slightly Less Painful

These are two commands for switching the Spotify proxy on and off, as Spotify doesn't automate it for you. Also bundled are some aliases you can use to switch from the command line.

  • Make sure you have your proxy settings set up and set to 'HTTP' or 'No Proxy'
  • Download the two .command files
  • Save them somewhere sensible
  • Make sure they are executable (Move to the directory you saved them in and chmod +x Spotify_Proxy_Off.command Spotify_Proxy_On.command)

Now you can proxy switch from Spotlight by searching Spotify Proxy On and Spotify Proxy Off 🤗

The use of pgrep and pkill is not bulletproof but it is fast!

alias sproxon='
if pgrep -x "Spotify" > /dev/null
then
echo "Spotify is running."
spotify_kill; spotify_proxy_on && spotify_open
else
echo "Spotify is not running."
fi'
alias sproxoff='
if pgrep -x "Spotify" > /dev/null
then
echo "Spotify is running."
spotify_kill; spotify_proxy_off && spotify_open
else
echo "Spotify is not running."
fi'
alias spotify_kill='pkill Spotify'
alias spotify_open='open -a Spotify'
alias spotify_proxy_on='sed -i -e "s/network.proxy.mode=1/network.proxy.mode=2/" ~/Library/Application\ Support/Spotify/prefs'
alias spotify_proxy_off='sed -i -e "s/network.proxy.mode=2/network.proxy.mode=1/" ~/Library/Application\ Support/Spotify/prefs'
if pgrep -x "Spotify" > /dev/null
then
echo 'Spotify is running. Restarting.'
pkill Spotify
sed -i -e "s/network.proxy.mode=2/network.proxy.mode=1/" ~/Library/Application\ Support/Spotify/prefs
open -a Spotify
else
echo 'Spotify is not running.'
fi
if pgrep -x "Spotify" > /dev/null
then
echo 'Spotify is running. Restarting.'
pkill Spotify
sed -i -e "s/network.proxy.mode=1/network.proxy.mode=2/" ~/Library/Application\ Support/Spotify/prefs
open -a Spotify
else
echo 'Spotify is not running.'
fi
@macataxis
Copy link

macataxis commented Apr 10, 2018

Tnx for this.
Rewrote a couple of lines to make this switcher ping an internal network and put proxy on or off from the response.

#!/bin/bash
if ping -c 1 "some internal host" &> /dev/null
then
pkill Spotify
sed -i -e "s/network.proxy.mode=1/network.proxy.mode=2/" ~/Library/Application\ Support/Spotify/prefs
open -a Spotify
else
pkill Spotify
sed -i -e "s/network.proxy.mode=2/network.proxy.mode=1/" ~/Library/Application\ Support/Spotify/prefs
open -a Spotify
fi

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment