Last active
April 13, 2020 01:26
-
-
Save jsfaint/a6c87a21efe45f5bc86d to your computer and use it in GitHub Desktop.
Set System Proxy for OS X
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
wifi="Wi-Fi" | |
IP=127.0.0.1 | |
PORT=7777 | |
[[ $# -ne 1 ]] && echo "$0 http|pac|disable" && exit 1 | |
flag=$1 | |
function webproxy_set() { | |
[[ $# -ne 1 ]] && return | |
if [[ x$1 == x"on" ]]; then | |
sudo networksetup -setwebproxy "$wifi" $IP $PORT | |
sudo networksetup -setsecurewebproxy "$wifi" $IP $PORT | |
else | |
sudo networksetup -setwebproxystate "$wifi" off | |
sudo networksetup -setsecurewebproxystate "$wifi" off | |
fi | |
} | |
function pac_set() { | |
[[ $# -ne 1 ]] && return | |
if [[ x$1 == x"on" ]]; then | |
sudo networksetup -setautoproxyurl "$wifi" http://$IP:$PORT/pac | |
else | |
sudo networksetup -setautoproxystate "$wifi" off | |
fi | |
} | |
if [[ x$flag == x"http" ]]; then | |
echo "Set http/https proxy" | |
webproxy_set on | |
pac_set off | |
elif [[ x$flag == x"pac" ]]; then | |
echo "Set autoproxyurl as 'http://$IP:$PORT/pac'" | |
webproxy_set off | |
pac_set on | |
else | |
echo "Disable all proxy" | |
webproxy_set off | |
pac_set off | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment