In OS X, you turn on and off a web proxy from System Preferences > Network > Proxies, by checking Web Proxy (HTTP) and designating the Web Proxy Server etc. and by clicking OK a
To just toggle on/off my proxies in OSX Mavericks, I set up this script. Note that this example just affects my wi-fi adapter. I am toggling on/off the web, streaming, and SOCKS proxies all at once. You could set the proxy address as well, per Gordon's example, but I already had this saved through the System Preferences > Network > Proxies GUI.
BASH Script, saved as prox.sh:
#!/bin/bash
e=$(networksetup -getwebproxy wi-fi | grep "No")
if [ -n "$e" ]; then
echo "Turning on proxy"
sudo networksetup -setstreamingproxystate wi-fi on
sudo networksetup -setsocksfirewallproxystate wi-fi on
sudo networksetup -setwebproxystate wi-fi on
else
echo "Turning off proxy"
sudo networksetup -setstreamingproxystate wi-fi off
sudo networksetup -setsocksfirewallproxystate wi-fi off
sudo networksetup -setwebproxystate wi-fi off
fi
Then symlink the script on the command line:
ln -s /Script/Location/prox.sh prox-toggle
Now you can toggle the proxies on/off at the command line:
bash prox-toggle