Hello, I am just starting with KM but already felt it's tremendous potencial. I am trying to build a macro to check/uncheck proxies settings when I switch from home to work wireless network.
Please use this AppleScript in KM to select the buttons, simply replace the word "Ask to join new networks" with the exact name of the checkbox you would like to select.
Everytime the script below executes it will automatically tick and then untick if you execute it again.
activate application "System Preferences"
tell application "System Events"
tell process "System Preferences"
click checkbox 1 of row 1 of table 1 of scroll area "Select a protocol to configure:" of group 1 of tab group 1 of sheet 1 of window "Network"
end tell
end tell
However, if you need to get the value before you execute the above script for an IF statement then you can use
activate application "System Preferences"
tell application "System Events"
tell process "System Preferences"
get value of checkbox 1 of row 1 of table 1 of scroll area "Select a protocol to configure:" of group 1 of tab group 1 of sheet 1 of window "Network"
end tell
end tell
If result value is 0 then it is unticked
If result value is 1 then it is ticked
Thanks so much for you all, for your prompt reply. Here's the feedback:
the first and second scripts, by @demirtas1 and @CJK only worked, strangely enough, in row 1, it doesn't work for the other rows, and I needed a click on row's 3 and 4. I could see it clicks on the box, but it doesn't mark/unmark the checkbox (except in row 1), not altering thus the proxy settings.
the third shell script, by @OscarGong, worked like a charm, with the advantage of setting/desetting proxy even with System Preferences closed, which is very handy.
I've used UI Browser to get the attributes of the checkbox, thanks @DanThomas, but it is indeed quite expensive, though doing a great job. Two thoughts remain:
is there a free app to get the attributes of UI's?
@Ricabude, correction: I didn’t contribute any scripts, they were both from @demirtas1. I only replied to that post to inform him that they wouldn't work because of a clear oversight.
I think a simpler solution would be to create a new Location with your desired proxy settings and create a Macro to switch to that location when you are on the work network. I have something similar to switch to a manual IP address on my home network. See below. Melon is my home network.