This is a follow-up to a post made about 2 years ago to use Apple Script to switch between Wi-Fi networks via the menu bar:
Big Sur 11.1: AppleScript to Automatically Change Wi-Fi Networks
My previously-working script now just returns "missing value":
tell application "System Events" to click (every menu bar item of menu bar 1 of application process "ControlCenter" whose title starts with "Wi‑Fi")
tell application "System Events" to click (every UI element of scroll area of group 1 of window "Control Center" of application process "ControlCenter" whose title starts with "YOUR_SSID_HERE")
It seems macOS Ventura broke my previously solution pretty badly. I can't even use "get properties" to make any sense of of what the hierarchy of UI elements should be anymore. Eg:
tell application "System Events" to click (every menu bar item of menu bar 1 of application process "Control Center" whose description starts with "Wi‑Fi")
delay 3
tell application "System Events" to get properties of UI elements of scroll area 1 of group 1 of window "Control Center" of application process "Control Center"
Result:
{{minimum value:missing value, orientation:missing value, position:{2061, 76}, class:UI element, accessibility description:missing value, role description:"heading", focused:missing value, title:missing value, size:{102, 15}, help:missing value, entire contents:{}, enabled:true, maximum value:missing value, role:"AXHeading", value:missing value, subrole:missing value, selected:missing value, name:missing value, description:"heading"}, {minimum value:missing value, orientation:missing value, position:{2052, 95}, class:checkbox, accessibility description:missing value, role description:"toggle button", focused:missing value, title:missing value, size:{288, 32}, help:missing value, entire contents:{}, enabled:true, maximum value:missing value, role:"AXCheckBox", value:0, subrole:"AXToggle", selected:missing value, name:missing value, description:"toggle button"}, {minimum value:missing value, orientation:missing value, position:{2061, 141}, class:UI element, accessibility description:missing value, role description:"heading", focused:missing value, title:missing value, size:{99, 15}, help:missing value, entire contents:{}, enabled:true, maximum value:missing value, role:"AXHeading", value:missing value, subrole:missing value, selected:missing value, name:missing value, description:"heading"}, {minimum value:missing value, orientation:missing value, position:{2052, 160}, class:checkbox, accessibility description:missing value, role description:"toggle button", focused:missing value, title:missing value, size:{288, 32}, help:missing value, entire contents:{}, enabled:true, maximum value:missing value, role:"AXCheckBox", value:0, subrole:"AXToggle", selected:missing value, name:missing value, description:"toggle button"}, {minimum value:missing value, orientation:missing value, position:{2052, 192}, class:checkbox, accessibility description:missing value, role description:"toggle button", focused:missing value, title:missing value, size:{288, 32}, help:missing value, entire contents:{}, enabled:true, maximum value:missing value, role:"AXCheckBox", value:1, subrole:"AXToggle", selected:missing value, name:missing value, description:"toggle button"}, {minimum value:missing value, orientation:missing value, position:{2052, 224}, class:checkbox, accessibility description:missing value, role description:"toggle button", focused:missing value, title:missing value, size:{288, 32}, help:missing value, entire contents:{}, enabled:true, maximum value:missing value, role:"AXCheckBox", value:0, subrole:"AXToggle", selected:missing value, name:missing value, description:"toggle button"}, {minimum value:missing value, orientation:missing value, position:{2052, 267}, class:UI element, accessibility description:missing value, role description:"disclosure triangle", focused:false, title:missing value, size:{288, 22}, help:missing value, entire contents:{}, enabled:true, maximum value:missing value, role:"AXDisclosureTriangle", value:0, subrole:missing value, selected:missing value, name:missing value, description:"disclosure triangle"}}
This is total gibberish to me and doesn't list any clear UI elements with any name or description attributes that point to a specific Wi-Fi SSID. I also notice a ton of "missing value" strings. By comparison, using Accessibility Inspector and clicking on my desired SSID in the network list, it claims it has the below attributes:
<AXApplication: “Control Center”>
<AXWindow: “Control Center”>
<AXGroup>
<AXScrollArea>
<AXCheckBox>
Attributes:
AXParent: “<AXScrollArea>”
AXRoleDescription: “toggle button”
AXChildren: “<array of size 0>”
AXIdentifier: “wifi-network-MYSSID”
AXPath: “Path 0x600003016d90:
”
AXAttributedDescription: “MYSSID, secure network, 3 bars{
AXATextAlignmentValue = 0;
AXFont = {
AXFontFamily = ".AppleSystemUIFont";
AXFontName = ".SFNS-Regular";
AXFontSize = 13;
AXVisibleName = "System Font Regular";
};
AXForegroundColor = <CGColor 0x6000026161c0> [<CGColorSpace 0x600002620ae0> (kCGColorSpaceICCBased; kCGColorSpaceModelRGB; Generic RGB Profile)] ( 0 0 0 0.847059 );
}”
AXEnabled: “1”
AXSubrole: “AXToggle”
AXRole: “AXCheckBox”
AXWindow: “<AXWindow: “Control Center”>”
AXValue: “1”
AXChildrenInNavigationOrder: “<array of size 0>”
Actions:
AXPress - press
I'm really truly stumped here and have been trying to work on this for hours. I just can't for the life of me figure out which child element within "scroll area 1" I should be using. Any ideas?
Thanks.