Last active
January 17, 2020 15:22
-
-
Save BigSully/0e59ab97f148bc167ea19dbd42ebef4b to your computer and use it in GitHub Desktop.
toggle system proxy by hammerspoon shortcuts in macos
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
1. set the ip and port of http and https proxy manually for the first time, which can be accomplished in command line though. | |
networksetup -setwebproxy "Wi-fi" 127.0.0.1 8080 | |
networksetup -setsecurewebproxy "Wi-fi" 127.0.0.1 8080 | |
2. add the following shell function to your ~/.profile | |
toggleProxy() { | |
e=$(networksetup -getwebproxy wi-fi | grep "No") | |
ns=wi-fi | |
status='' | |
if [ -n "$e" ]; then | |
status=on | |
else | |
status=off | |
fi | |
echo -n "Turning $status proxy" | |
networksetup -setstreamingproxystate $ns $status | |
networksetup -setsocksfirewallproxystate $ns $status | |
networksetup -setwebproxystate $ns $status | |
networksetup -setsecurewebproxystate $ns $status | |
} | |
3. add the following to your ~/.hammerspoon/init.lua | |
hs.hotkey.bind({"cmd", "alt", "ctrl"}, "P", function() | |
local output = hs.execute("toggleProxy", true) | |
hs.alert.show(output) | |
end) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment