Skip to content

Instantly share code, notes, and snippets.

@genevera
Last active June 15, 2016 19:47
Show Gist options
  • Select an option

  • Save genevera/cb486d6ddff4cb4035aa73567d338469 to your computer and use it in GitHub Desktop.

Select an option

Save genevera/cb486d6ddff4cb4035aa73567d338469 to your computer and use it in GitHub Desktop.
Toggle web proxy via command-line (cli) in Mac OS X
# use sudo else you'll need to deal with a popup auth dialog.
#
# you can also add yourself to the sudoers file with NOPASSWD for this particular command.
# e.g. genevera ALL = (genevera) NOPASSWD: /usr/sbin/networksetup
# then you won't need to enter a pw at all for this :)
proxytoggle () {
if [[ $(networksetup -getwebproxy Wi-Fi | grep -c Yes) -eq 1 ]]
then
export http_proxy=
export https_proxy=
for _proxy in webproxy securewebproxy
do
sudo networksetup -set${_proxy}state Wi-Fi off
done
else
export http_proxy=http://$CACHE_IP:$CACHE_PORT
export https_proxy=https://$CACHE_IP:$CACHE_PORT
for _proxy in webproxy securewebproxy
do
sudo networksetup -set${_proxy}state Wi-Fi on
done
fi
networksetup -getwebproxy Wi-Fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment