So, like a consumer reported right here on Stack Change, the built-in “networksetup” command in terminal is fairly unreliable at occasions. It is sluggish, and I’ve discovered for some purpose dot1x by no means really establishes correctly for some kinds of Wi-Fi networks in my residence. The answer: Create an AppleScript to simulate mouse clicks on the menubar to alter between Wi-Fi networks.
Why is networksetup so sluggish in comparison with manually altering Wi-Fi networks?
The beneath script has labored wonderful for me till Large Sur:
use software "System Occasions"
property course of : a reference to software course of "SystemUIServer"
property menu bar : a reference to menu bar 1 of my course of
property menu bar merchandise : a reference to (menu bar gadgets of my menu bar ¬
the place the outline accommodates "Wi-Fi")
property menu : a reference to menu 1 of my menu bar merchandise
property menu merchandise : a reference to menu gadgets of my menu
to joinNetwork given title:ssid as textual content
native ssid
if not (my menu bar merchandise exists) then return false
click on my menu bar merchandise
repeat till my menu exists
delay 0.5
finish repeat
set M to a reference to (my menu merchandise the place the title accommodates ssid)
repeat 20 occasions --> 10 seconds @ 0.5s delay
if M exists then exit repeat
delay 0.5
finish repeat
click on M
finish joinNetwork
joinNetwork given title:"my community ssid"
The explanation why it broke is that Wi-Fi is not technically a direct choice underneath the primary menu bar. As a substitute, it is relegated to the Management Heart in Large Sur, and I believe there could even be one other sub-module it is technically nested it inside the UI. I have been studying for hours about folks attempting to beat this problem in Large Sur, for instance, to automate a click on on particular Bluetooth machine, however many AppleScripts folks wrote apparently broke within the 11.1 replace, and I’ve no simple start line right here for the way to determine the right way to accomplish what I’m attempting to do for Wi-Fi.
Any assist right here can be tremendously appreciated.
Aspect observe: I do know the identical consumer additionally posted a way utilizing AppleScriptObjC, however as folks identified, it is an enormous safety threat as a result of you must put your password someplace as plaintext. The UI script is subsequently the higher choice in my thoughts, so I might wish to get it to work once more.