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
Enabling and Disabling Proxy with a keyboard shortcut
In terminal, you can turn wifi proxy off and on with these commands
networksetup -setwebproxystate Wi-Fi
networksetup -setsecurewebproxystate Wi-Fi
and Ethernet
networksetup -setwebproxystate Ethernet
networksetup -setsecurewebproxystate Ethernet
Here's a one-liner to toggle between on and off (Using Wi-Fi example)
e=$(networksetup -getwebproxy wi-fi | grep "No")
if [ -n "$e" ]; then
networksetup -setwebproxystate Wi-Fi on
networksetup -setsecurewebproxystate Wi-Fi on
else
networksetup -setwebproxystate Wi-Fi off
networksetup -setsecurewebproxystate Wi-Fi off
fi
Create a keyboard shortcut that runs a shell command
Start Automator, and create a new Service.
Set "Service receives selected: to "no input" in "any application".
Add an action named "Run Shell Script". It's in the Utilities section of the Actions Library.
Insert the bash command you want into the text box and test run it using the Run button (top right). It should do whatever the script does (off, on or toggle), and there should be green ticks below the Action.
Save it, giving it a service name you can remember.
Go to System Preferences -> Keyboard, and go to the Shortcuts tab
Go to the Services section, and scroll down to General - you should find your service there. If you select the line, you can click "add shortcut" and give it a keyboard shortcut.