Skip to content

Instantly share code, notes, and snippets.

@waldekmastykarz
Created December 11, 2023 19:00
Show Gist options
  • Save waldekmastykarz/7b9139c87911fe95c7aaeda08e88c9eb to your computer and use it in GitHub Desktop.
Save waldekmastykarz/7b9139c87911fe95c7aaeda08e88c9eb to your computer and use it in GitHub Desktop.
Toggle macOS proxy settings
#!/bin/bash
arg1=$1
# Get the list of network services
network_services=$(networksetup -listallnetworkservices | tail -n +2)
if [[ "$arg1" == "on" ]]; then
while IFS= read -r service; do
networksetup -setwebproxy "$service" 127.0.0.1 8000
done <<<"$network_services"
elif [[ "$arg1" == "off" ]]; then
while IFS= read -r service; do
# Disable proxy on the network service
networksetup -setwebproxystate "$service" off
done <<<"$network_services"
else
echo "Set the argument to on or off."
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment