The “Automatic Proxy Configuration” url in System Preferences is used to point the clients to a PAC file to set the proxy server when on the Office LAN. Below are some scripts to manage this setting.
1. This version will only set the “Automatic Proxy Configuration” url for the defined services.
2. This version will set the “Automatic Proxy Configuration” url for all services.
If you happen to want to turn off this setting, the below will turn it off for all interfaces:
Whilst the above will turn off the “Automatic Proxy”, it doesn’t clear it. Sadly there is no way via the networksetup command to remove an “Automatic Proxy URL” once set.
If this bothers you, then then below will set the “Automatic Proxy URL” to ” “. It works the same as clearing the URL, but the space will show when typing into the URL field.
Bit confused why there are two scripts. They look the same.
Ah I see sorry. Either for a PAC file or url
doesn’t work for me and looks very confusing. I use this
#!/bin/bash
######## HARDCODED VALUES ARE SET HERE #########
pacfile=”file://localhost/proxy.pac”
Eth=’Ethernet’
Eth1=’Ethernet 1′
Eth2=’Ethernet 2′
Air=’AirPort’
Wi=’Wi-Fi’
#################################################
if
networksetup -listallnetworkservices | grep “${Eth}”
then
networksetup -setautoproxyurl “${Eth}” “${pacfile}”
else
echo ” There is not a service for “${Eth}” no need to set the pac file”
fi
if
networksetup -listallnetworkservices | grep “${Eth1}”
then
networksetup -setautoproxyurl “${Eth1}” “${pacfile}”
else
echo ” There is not a service for “${Eth1}” no need to set the pac file”
fi
if
networksetup -listallnetworkservices | grep “${Eth2}”
then
networksetup -setautoproxyurl “${Eth2}” “${pacfile}”
else
echo ” There is not a service for “${Eth2}” no need to set the pac file”
fi
if
networksetup -listallnetworkservices | grep “${Air}”
then
networksetup -setautoproxyurl “${Air}” “${pacfile}”
else
echo ” There is not a service for “${Air}” no need to set the pac file”
fi
if
networksetup -listallnetworkservices | grep “${Wi}”
then
networksetup -setautoproxyurl “${Wi}” “${pacfile}”
else
echo ” There is not a service for “${Wi}” no need to set the pac file”
fi
There are many ways to skin a cat!
The difference between your script & mine is that yours repeats the same steps 6 times.
Where mine runs once & loops through the variables.
Incidentally, what error do you get?
Please clarify why you have two scripts. What does script one do and what does script two do. Do they need to run together?
Please can you see script two. Is there information missing under
# 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
Problem is what if the script needs to work on 10.7 and 10.6? Service names are different? Granted not the most elegant way using loads of if statements 🙂
from the 1st script:
#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
So unless you rename your interfaces.. this will set proxies for Ethernert, VPN, AirPort or Wi-Fi.. which also covers 10.6 & 10.7 🙂
Updated: This 2nd script will set the ”Automatic Proxy Configuration” url in System Preferences for all network services.. if you’re not choosy & just wish this setting applied to all network services.
Ah great thanks very much 🙂 I must have got confused some where causing things to fail. Great stuff will give it a go.
Thanks very much script 1 works great 🙂
Is there a way to clear the autoproxyurl back to (null) via the command-line?
There is nothing supported, but a hack is to set it to “”. Seems to work for us.
We’re removing the PAC (woohoo), so post updated with a script that answers your question.
Instead of going thru all the available adapter is there a way to just verify if an virtual adapter created by a VPN Client is present and then update that adapter with the autoconfig script.
I apologize guys I’m kinda new to “scripting” any help would be greatly appreciated.
Where are the scripts? I think I might be missing something here, as I can’t seem to find a download link, or link to the 2 scripts.
Try another browser. Works fine in Safari.
I tried the PAC file script for all services and it works great! However, it doesn’t seem to enforce the setting. Is there anything else I need to do other than specify the PAC file URL? Sorry, new to Proxy settings on Macs. Thanks.
It should be a remote & not local file.. is it?
Cannot see the scripts in either Safari or Mozilla Firefox.
odd.. working fine here on various versions of Safari (including iOS).
Hi Ben,
Love your work with this, can you confirm that this script works with OSX 10.11 variants?
Hi, it should. I no longer use this myself. But am not aware of any changes that would stop it from working.
Getting an error on one device.
“Script result: /Library/Application Support/JAMF/tmp/Auto Proxy Config: line 45: networksetup: command not found
Auto proxy present, correct & enabled for all interfaces”
Any ideas?
Jordan, I made a little amend. Can you try again?
Also, what does the below output:
which networksetup
Excellent script. I’ve added the following for my own needs to turn off any previously set explicitly defined proxies now that we are using a PAC file that works (previous version my company uses wasn’t working with the Mac uses). Others might find this useful to add to the script for themselves.
# Disable specific proxy settings for for all other settings
/usr/sbin/networksetup -setftpproxystate “$i” off
echo “Turned off ftp proxy state for $i”
/usr/sbin/networksetup -setwebproxystate “$i” off
echo “Turned off web proxy state for $i”
/usr/sbin/networksetup -setsecurewebproxy “$i” off
echo “Turned off secure web proxy state for $i”
/usr/sbin/networksetup -setstreamingproxystate “$i” off
echo “Turned off streaming proxy state for $i”
/usr/sbin/networksetup -setgopherproxystate “$i” off
echo “Turned off gopher proxy state for $i”
/usr/sbin/networksetup -setsocksfirewallproxystate “$i” off
echo “Turned off socks firewall proxy state for $i”
One question, have you managed to loop this through all network locations without first switching the active location to the one you want to modify? Meaning, I have remote users with laptops who may have 2 or more locations as a result of our prior proxy woes. While I could delete those locations I’d prefer to simply update them remotely behind the scenes. Obviously we can list locations but I haven’t managed to find a way to make changes to those that aren’t currently active.
Thanks!
Have the original scripts been removed? I cant see them ?
I can’t either. Have you found them? I’ve tried Safari and Opera.
They are there.
I’m using a plugin which renders the scripts from GitHub, they are working fine for me.
Great script, 2 is working for me. Anyway to also set the proxy bypass info at the same time for all services?
20 minutes of studying your script and I managed to add in proxy bypass as well 🙂
i cant get the script to run.. i get a lot of command not found errors starting from line 25.
i am using the script that adds the proxy server to all services.
live 25 is
#Loops through the list of network services
really not sure whats going on… any ideas?
ok so i managed to get your script working.
had to chop and change it a bit but i got there in the end…. i removed a few sections that i just simply couldnt get to run correctly.
the script runs during logon via jamf.
i just tested it and it definitely applied the pac file to all interfaces.
#!/bin/sh
####################################################################################################
#
# More information: https://macmule.com/2014/12/07/how-to-change-the-automatic-proxy-configuration-url-in-system-preferences-via-a-script/
#
# GitRepo: https://github.com/macmule/setAutomaticProxyConfigurationURL
#
# License: https://macmule.com/license/
#
####################################################################################################
# HARDCODED VALUES ARE SET HERE
autoProxyURL=”pac.file”
#echo “$autoProxyURL”
/usr/sbin/networksetup -detectnewhardware
IFS=$’\n’
for i in $(networksetup -listallnetworkservices | tail +2)
do
#echo “network interface: $i”
/usr/sbin/networksetup -setautoproxyurl $i $autoProxyURL
echo “set auto proxy for $i to $autoProxyURL”
/usr/sbin/networksetup -setautoproxystate “$i” on
echo “Turned on auto proxy for $i”
done
unset IFS
i will test with a few more users but so far so good.
thanks!
Has anyone attempted to add anything to the “Bypass proxy settings for these Hosts & Domains:” field with this script?
Thanks