1

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.

3
  • 2
    That is one of the problems with GUI scripting - you need to figure out the new object hierarchy when it gets changed.
    – red_menace
    Oct 29, 2022 at 23:27
  • Why not simply use the Fast User Switching option in the Menu Bar?
    – Titanium
    Nov 2, 2022 at 20:47
  • Because I want a keyboard shortcut for it. I use Fast Scripts to assign shortcuts to scripts.
    – Barmar
    Nov 2, 2022 at 21:56

1 Answer 1

0

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .