If not, at least go directly to Proxies?
I am constantly having to turn my proxy on (useful but slow) and off.
Thanks in advance for your time and help.
If not, at least go directly to Proxies?
I am constantly having to turn my proxy on (useful but slow) and off.
Thanks in advance for your time and help.
Hey @ronald,
Why not create a couple of network locations – one with Automatic Proxy Configuration ON and one with APC OFF.
Then you can just switch between with the Set Network Location action.
I have not actually done this myself and cannot therefore recommend it as a definitive working solution – but a little research suggests it ought to do the job.
Give it a try, before you monkey with scripted solutions.
-Chris
thank you for your reply. You are 100% right.
I did that yesterday and even have the macro ready to switch locations and have spent the last day trying to figure out why the duplicate Ethernet network is not connected and does not have an IP address.
So I started with duplicate of Ethernet location which works perfectly→ called the duplicate proxy
Error message below (does not have an IP address)
What I tried after many google searches
In an act of desperation, I posted to this forum.
thanks again
Well, that's no fun...
I had a hard time scripting this for Mojave and getting it to work reliably...
This script as is will likely NOT work with systems more advanced that Mojave without adjustments. For instance "System Settings" instead of "System Preferences".
It's also likely that the UI will be a bit different, and I cannot help with that at this time.
tell application "System Preferences"
activate
reveal pane id "com.apple.preference.network"
end tell
tell application "System Events"
tell application process "System Preferences"
repeat while name of front window is not "Network"
delay 0.2
end repeat
tell window "Network"
repeat while (exists of button "Advanced…") is false
delay 0.2
end repeat
tell button "Advanced…"
perform action "AXPress"
end tell
tell sheet 1
tell tab group 1
tell radio button "Proxies"
perform action "AXPress"
delay 0.1
end tell
tell group 1
tell scroll area 1
tell table 1
set proxyRow to first item of (get rows where its text field 1's value is "Automatic Proxy Configuration")
tell proxyRow
set its selected to true
tell its checkbox 1
perform action "AXPress"
end tell
end tell
end tell
end tell
end tell
end tell
end tell
end tell
end tell
end tell
OK I will have a look. Thanks VERY much !
Assuming your network connection is called "Ethernet", as per the screenshot, the Terminal command (using a full path to the utility):
/usr/sbin/networksetup -setautoproxystate "Ethernet" on
...should work, And change "on" to "off" to turn it off again.
So in KM:
Fantastic solution. Thank you so much !
I tested proxy on / off with your script and all worked perfectly, except for one minor glitch.
When I manually turn the proxy on the first time, I check the automatic proxy configuration box and fill in the URL (format http://proxy.university.edu)
After that I can just check it on and off manually without having to fill in the URL field.
When I turn the proxy on and off with the terminal script, sometimes the turn off script also deletes the URL which is than absent when I turn the proxy back on.
1- would you perhaps know if there is a way to add the URL to the proxy ON shell script ? If not, it's fine. I can live with it. If I turn it ON and it does not work, I will know that the URL must be missing.
2- this is a typical situation where I would want to toggle between 2 actions ie proxy on - off (to which I would add notifications). I could use a "proxy"conflict palette, user input, if then else, etc. How would you handle this. I was wondering which method is the most elegant for an advanced user.
thanks ... a million !
/usr/sbin/networksetup -setautoproxyurl "Ethernet" "http://proxy.university.edu"
It isn't a problem if you set it even if already set, so:
Typically -- I wouldn't! With no UI indication of the current proxy setting I'd rather explicitly set it when I wanted it and explicitly turn it off when I didn't.
And, unlike most arguments in networksetup
, there's no corresponding -get
for -setautoproxystate
. Is this the only interface you'll be using auto proxy config on? If so you could check /Library/Preferences/SystemConfiguration/preferences.plist
for the string ProxyAutoConfigEnable = 1;
-- if it's there then it's set.
defaults read /Library/Preferences/SystemConfiguration/preferences.plist | grep "ProxyAutoConfigEnable = 1;"
I'd do that as part of the same "Execute Shell Script" action so it's all done in one go rather than spawning a shell, exiting that and going back to KM to make a decision, then spawning another shell instance to make the change.
If checking for that one setting isn't good enough, eg you've got an auto proxy on your WiFi as well, I'll dig a bit deeper.
great. I will test the shell grep command.
Quick question and I shall leave you in peace.
Is there an easy way to open the proxies tab in sys pref → Network Preferences→ Ethernet → Advanced → Proxies
I can only get as far as opening the network preferences interface.
thanks again
Given how Apple keep breaking accessibility in System Preferences/Settings, I'd probably go the KM image detection route rather than use AppleScript. (Part of the problem is that each interface has its own proxy setting, but the clickable "button" for each interface has no name -- you'd have filter through AXAttributedDescription
to get to the "Details" pane.)
To make up for that non-help -- after a bit of digging about, here's a shell script that will toggle your proxy setting on and off. I've again assumed the interface is called "Ethernet", but change line 3 if it isn't. It'll return "Proxy turned on/off" as suits, which you can use directly in a Notification or save to a variable.
#!/bin/bash
interfaceName="Ethernet"
uids=$( /usr/libexec/PlistBuddy -c "Print :NetworkServices" /Library/Preferences/SystemConfiguration/preferences.plist | perl -lne 'print $1 if /^ (\S*) =/' )
for uid in $uids
do
nicName=$( /usr/libexec/PlistBuddy -c 'Print :NetworkServices:'$uid':UserDefinedName' /Library/Preferences/SystemConfiguration/preferences.plist )
if [ "$nicName" = "$interfaceName" ]
then
proxOn=$( /usr/libexec/PlistBuddy -c 'Print :NetworkServices:'$uid':Proxies:ProxyAutoConfigEnable' /Library/Preferences/SystemConfiguration/preferences.plist 2>&1 )
if [ "$proxOn" = "1" ]
then
/usr/sbin/networksetup -setautoproxystate "$interfaceName" off
echo "Proxy turned off"
else
/usr/sbin/networksetup -setautoproxystate "$interfaceName" on
/usr/sbin/networksetup -setautoproxyurl "$interfaceName" "http://proxy.university.edu"
echo "Proxy turned on"
fi
fi
done
Proxy Toggle Shell Script.kmactions (1.6 KB)
absolutely great ! thanks very much !
Funny thing...
By playing around I discovered how easy it is to navigate network preferences because TCP/IP, DNS, etc, Proxies, etc all behave as buttons in terms of KM actions.
To go to proxies, I simply open preference pane with a KM action → press Advanced ... button → Press Proxies button.
After all the time I wasted trying to solve my issue with UI Browser before posting my question to this forum!