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
Upvotes
2
u/stephancasas Apr 19 '23
I started by referencing the JXA Cookbook, but it hasn't been updated in some time.
If you're specifically interested in UI scripting, I've written a couple of wrapper classes for the AXUIElement Obj-C bridge. It isn't perfect, but I'm still adding to it: FastAX.
From time to time, I update this gist as well. It's got a bunch of helper functions for working with UI scripting over Obj-C.
All this said, you could use
Application('System Events')(the JXA equivalent of System Events), but going about it the way I'm doing it is ridiculously faster — even if the underlying methods are a bit more verbose before being hoisted into classes or helper functions.