Expanding on swisscheese's answer for the specific case of the SOCKS5 proxy (i.e. the type generated with
ssh -D, shadowsocks, v2ray, etc).
Given that you configured the proxy server with e.g.
networksetup -setsocksfirewallproxy wi-fi localhost 1080
💡 interface name is not case sensitive
you can later turn it off with
networksetup -setsocksfirewallproxystate wi-fi off
and then back on with
networksetup -setsocksfirewallproxystate wi-fi on
I.e. the first command only needs to be run once, and then you can just activate/deactivate the proxy as needed.
GUI for setting proxies
Here is a bitbar plugin which wraps the commands above and makes them available as dropdown options in the macos menu bar. The plugin also supports http and PAC proxies. Bitbar is an open-source app that allows putting the output of any command to the menu bar (as well as launch any command via a bash/python/ruby/node/go script). Disclaimer: I'm not affiliated with the bitbar author.
Another GUI solution specifically for touch-bar users:
With MTMR you can use the
shellScriptTitledButton in the JSON config file to run a specific command from the mac touch-bar.