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
As I needed a simple script that will just toggle both HTTP and HTTPS proxies on/off at the same time, here it is:
#!/usr/bin/env bash
# Toggles *both* HTTP and HTTP proxy for a preconfigured service name ("Wi-Fi" or "Ethernet").
NETWORK_SERVICE_NAME="Wi-Fi" # Wi-Fi | Ethernet
IS_PROXY_ENABLED=$(networksetup -getwebproxy "$NETWORK_SERVICE_NAME" | head -n 1 | grep Yes)
if [ -z "$IS_PROXY_ENABLED" ]; then
echo "Enabling HTTP and HTTPs proxy for $NETWORK_SERVICE_NAME"
networksetup -setstreamingproxystate "$NETWORK_SERVICE_NAME" on
networksetup -setwebproxystate "$NETWORK_SERVICE_NAME" on
networksetup -setsecurewebproxystate "$NETWORK_SERVICE_NAME" on
else
echo "Disabling HTTP and HTTPs proxy for $NETWORK_SERVICE_NAME"
networksetup -setstreamingproxystate "$NETWORK_SERVICE_NAME" off
networksetup -setwebproxystate "$NETWORK_SERVICE_NAME" off
networksetup -setsecurewebproxystate "$NETWORK_SERVICE_NAME" off
fi