Posted on 06-05-2013 10:59 AM
Wanted to share a script that we just created. I think someone will find it most helpful when it comes to applying user locations on a corporate LAN.
#!/bin/sh
networksetup -createlocation "Office" populate
networksetup -createlocation "Public" populate
networksetup -switchtolocation "Office" populate
networksetup -deletelocation "Automatic" populate
networksetup -setairportpower en1 off
sleep 10
autoProxyURL="http://URL:8080"
# CHECK TO SEE IF A VALUE WAS PASSED FOR $4, AND IF SO, ASSIGN IT
if [ "$4" != "" ] && [ "$autoProxyURL" == "" ]; then
autoProxyURL=$4
fi
# Detects all network hardware & creates services for all installed network hardware
/usr/sbin/networksetup -detectnewhardware
IFS=$' '
#Loops through the list of network services
for i in $(networksetup -listallnetworkservices | tail +2 );
do
# Get a list of all services beginning 'Ether' 'Air' or 'VPN' or 'Wi-Fi'
# If your service names are different to the below, you'll need to change the criteria
if [[ "$i" =~ 'Ether' ]] || [[ "$i" =~ 'Air' ]] || [[ "$i" =~ 'VPN' ]] ; then
autoProxyURLLocal=/usr/sbin/networksetup -getautoproxyurl "$i" | head -1 | cut -c 6-
# Echo's the name of any matching services & the autoproxyURL's set
echo "$i Proxy set to $autoProxyURLLocal"
# If the value returned of $autoProxyURLLocal does not match the value of $autoProxyURL for the interface $i, change it.
if [[ $autoProxyURLLocal != $autoProxyURL ]]; then
networksetup -setautoproxyurl $i $autoProxyURL
echo "Set proxy for $i to $autoProxyURL"
fi
fi
done
echo "Proxies All Present And Correct..."
unset IFS
This script creates two locations "Office" and "Home" deletes automatic locations and turns off WIFI. It also waits 10 seconds and sets the Auto config proxy to a URL of choice.
Posted on 06-05-2013 11:35 AM
What a great script!
Thank you!
Posted on 03-14-2016 10:10 PM
Thanks for this! Combined your script with MacMules to create the locations then set AutoProxyURL for All office! https://macmule.com/2014/12/07/how-to-change-the-automatic-proxy-configuration-url-in-system-preferences-via-a-script/