http://bjoernstechblog.rueffer.info/posts/mac/proxy/networking/2010/03/29/turning-proxies-on-and-off-easily/
last updated on 25 May 2018

29 March 2010

turning proxies on and off easily

Proxies for MacOS X are to be configured in the network preferences, individually for each network interface. Sometimes, that’s not what you want, and Authoxy or FoxyProxy can be great tools. FoxyProxy in particular lets you switch between different proxies for Firefox, and also lets you turn them on and off easily or even automatically by certain URL patterns. Wouldn’t it be great to do similar things also for other programs, or, say Safari?

Using a little scripting, that’s indeed quite simple. For me, it is sufficient to turn on and off a proxy located in another country, allowing me to view certain online TV using Safari. But you could do more. The magic ingredient is networksetup, a command line tool to the network preference pane. Just look at the manpage for a list of available options.

And here’s my little script to turn on and off the proxy services, especially the streaming proxy is important for me, so that I don’t have to use the mouse to do that:

#!/bin/bash
# Copyright (C) 2010 by Bjoern Rueffer

usage() {     cat <<EOF
usage: proxy Airport|Ethernet on|off

This will switch all proxies (http,https,rtps) on/off for the named interface.
EOF
exit 1
}

if [ $# -ne 2 ]; then
 usage
fi
if ([ $1 != Airport ] && [ $1 != Ethernet ]) || \
	([ $2 != on ] && [ $2 != off ]); then
	usage
fi

sudo networksetup -setwebproxystate $1 $2;
sudo networksetup -setsecurewebproxystate $1 $2;
sudo networksetup -setstreamingproxystate $1 $2;     
Björn Rüffer — Copyright © 2009–2018 — bjoern.rueffer.info