My stupid ISP occasionally (and inconsistently) fails to load some sites unless I’m on their web proxy. As a result, I constantly have to do the network proxy toggling dance on my Mac (System Preferences → Network → Advanced → Proxies → checkbox).
Turns out this can be done with a [script](http://forums.macrumors.com/showthread.php?t=959704). In Lion, though, Apple’s renamed “AirPort” to “Wi-Fi”, so I’ve updated the scripts from the linked post:
* To enable the proxy, use `networksetup -setwebproxystate wi-fi on`
* To disable, use `networksetup -setwebproxystate wi-fi off`
Here’s a (very fragile) shell script to toggle your proxy, depending on whether it’s on:
#!/bin/bash
e=$(networksetup -getwebproxy wi-fi | grep "No")
if [ -n "$e" ]; then
echo "Turning on proxy"
networksetup -setwebproxystate wi-fi on
else
echo "Turning off proxy"
networksetup -setwebproxystate wi-fi off
fi
I’ve also packaged it as an extension for the extraordinarily useful launcher [Alfred](http://alfredapp.com), so I can just hit cmd-space, type in “proxy”, and it’ll toggle between the two states (with a handy Growl notification telling me what it just did). You can download it here.
Some notes:
* For all these scripts to work, you must already have the proxy set up in your Network Preferences.
* I believe these scripts only work on Lion — for Snow Leopard and before, try changing `wi-fi` to `airport`. Sorry, I don’t have any machines on 10.6 to test on!
* The script is fragile because it’ll break the moment Apple changes the output of `networksetup`. [Let me know](http://yjsoon.com/contact) if this happens, and I’ll try and fix it.