Toggle Proxy Settings on or off in Network>Advanced>Proxies pane.

I’ve been struggling with this bit of script and don’t seem to be able to accomplish it. Here’s what I’m trying to do:

tell application "System Preferences"
	reveal anchor "Proxies" of pane id "com.apple.preference.network" -- no problem to here.
	activate
	(* here I want code to toggle checkbox 1 of row 5 of table 1 of scroll area 1 of group 1 of tab group 1 of sheet 1 of window "Network" (according to UI Browser); i.e. turn the proxy on or off. The pane remembers the IP Address and port to use, so no need to set them. No amount of finagling will get the value or set that checkbox -- my attempts don't even compile*)
end tell

Hi Adam,

try this, on my machine the popup menu “Configure Proxies:” doesn’t remember the Manually setting,
so I added to select the menu item.
The trick is to select the row before clicking the checkbox :wink:


tell application "System Preferences"
	reveal anchor "Proxies" of pane id "com.apple.preference.network" -- no problem to here.
	activate
end tell

tell application "System Events"
	tell process "System Preferences"
		tell pop up button 1 of tab group 1 of sheet 1 of window "Network"
			click
			delay 0.2
			pick menu item "Manually" of menu 1
		end tell
		repeat until exists scroll area 1 of group 1 of tab group 1 of sheet 1 of window "Network"
			delay 0.2
		end repeat
		tell (1st row of table 1 of scroll area 1 of group 1 of tab group 1 of sheet 1 of window "Network" whose value of text field 1 is "SOCKS proxy")
			set value of attribute "AXSelected" to true
			click checkbox 1
		end tell
	end tell
end tell

Thanks, Stefan. The trick, as you put it, is also to identify the row you want not as the 5th row, but as the one whose value of text field 1 is “SOCKS proxy”. That’s the bit I didn’t get at all. After that, I’ve got to click the OK button to close the sheet, then the Apply button to do the deed, but I can manage that. Also, since I’d like to toggle this (for browsing over an SSH connection) so I’ll modify it to get the value of attribute “AXSelected” so I can flip it. Again, thanks.