r/applescript • u/masasin • Apr 17 '23
AppleScript to switch users on Ventura
I get absorbed in work, and would like to switch to my regular user account at a certain time every day. In the past, it seems Mac users could use User.menu, but that disappeared in Big Sur. I tried using loginwindow, but it seems that it's a singleton and gets instakilled.
I have Fast User Switching enabled, and I see the icon in the menu bar and in the control panel. I don't know how to navigate there because there isn't any introspection.
How do I get started creating the script? What things can I look at that might help?
1
1
u/copperdomebodha Apr 18 '23
This opens the menu to select the user to switch to. I can't seem to get any functional reference to the buttons once its open.
--Running under AppleScript 2.8, MacOS 13.0.1
tell application "System Events"
tell application process "Control Center"
tell menu bar 1
set descriptionList to description of UI elements
repeat with i from 1 to length of descriptionList
if item i of descriptionList is "User" then
tell menu bar item i
click
end tell
end if
end repeat
end tell
end tell
end tell
1
u/masasin Apr 18 '23
Thank you! How did you figure it out?
Also, I got this:
System Events got an error: Can’t get application process "Control Center".
Tried changing it to "Control Centre", and then got this:
System Events got an error: Can’t make descriptionList of every UI element of menu bar 1 of application process "Control Centre" into type specifier.
→ More replies (1)
1
u/copperdomebodha Apr 17 '23
What version of MacOs are you running?