Skip to content

Instantly share code, notes, and snippets.

@joncardasis
Created July 15, 2016 19:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joncardasis/d779ef9d47d075686c1fca41d48f01de to your computer and use it in GitHub Desktop.
Save joncardasis/d779ef9d47d075686c1fca41d48f01de to your computer and use it in GitHub Desktop.
Bash script to set network proxies for network interfaces in OSX
#!/bin/bash
# Set automatic network proxies in System Preferences
# The specified proxy url below will be set for both the Ethernet and Wi-Fi interfaces
PROXY_URL="http://www.example.com/proxy.js" #automatic-proxy url
###########
LISTED_NETWORK_SERVICES=$(networksetup -listallnetworkservices | sed '/An asterisk ([*]) denotes that a network service is disabled./d; s/^[*]//')
IFS=$'\n' SERVICES=($LISTED_NETWORK_SERVICES) #Separate string into array of services
for netService in "${SERVICES[@]}"; do
if [[ $netService == *"Ethernet"* ]] || [[ $netService == *"Wi-Fi"* ]]; then
#If the service is an Ethernet or Wi-Fi interface
sudo networksetup -setautoproxyurl "$netService" "$PROXY_URL"
echo "Added proxy for [$netService] interface"
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment