AppleScript – Fast User Switch Stopped Working in Ventura

applescriptventura

In Monterey I've been using the AppleScript from AppleScript to automate switching user not working in Monterey to switch from my regular account to the admin account.

tell application "System Events"
    tell application process "Control Center"
        click (first menu bar item of menu bar 1 ¬
            whose value of attribute "AXIdentifier" is "com.apple.menuextra.user")
        click (first button of window "Control Center" whose name is "Administrator")
    end tell
end tell

Today I upgraded to Ventura and it stopped working. The error it gets is:

System Events got an error: Can’t get button 1 of window "Control Center" of application process "Control Center" whose name = "Administrator". Invalid index.

Best Answer

I haven't figured out how to do it by name yet, but if you know the button number you can specify it that way.

Also, the contents of the fast user switching window are now in a group within the window...

tell application "System Events"
    tell application process "Control Center"
        click (first menu bar item of menu bar 1 ¬
            whose value of attribute "AXIdentifier" is "com.apple.menuextra.user")
        click (button 2 of group 1 of window "Control Center")
        -- click (first button of window "Control Center" whose name is "Administrator")
    end tell
end tell