5

In macOS Mojave, I found that you could make an Automator app that allowed fast user switching by a hot key. The command run was

/System/Library/CoreServices/Menu\ Extras/User.menu/Contents/Resources/CGSession -switchToUserID `id -u XXXXXX`

With the Automator App, I could assign a hot key which would then run the command easily without any mouse interaction.

I'm now setting up a Big Sur computer and trying switch to a different user by a hot key. The script above does not work now and gives a no such file error. I'm wondering if there is another way to switch to a userid or a different command to use in order to do this?

3 Answers 3

4

User.menu along with other menu items were incorporated into Control Center in Big Sur, which removed the menu item package from Menu Extras. Gone with it is CGSession.

There does not appear to be an immediate replacement, and while workarounds for some of its other functionality have been developed, nothing for fast user switching yet.

2
  • 2
    Thank you for the information and that's too bad. I did find a work around for this, which works pretty well. I am using a MacBook Pro M1 so with a Touch Bar. If you touch the touchID for 1/2 sec or so it will ask you to switch users by clicking. So now can switch back and forth pretty easily by using the correct fingerprint for that user.
    – You Me
    Dec 28, 2020 at 21:05
  • This is a genius find - thank you!
    – jkp
    Jun 7, 2023 at 4:25
0

In Big Sur, you can set up a keyboard shortcut to switch users as follows.

  1. Go to System Preferences > Dock & Menu Bar > Fast User Switching
  2. Enable Show in Menu Bar
  3. Go to System Preferences > Security & Privacy > Privacy > Accessibility
  4. Add Automator and System Preferences to the list of apps allowed to control your computer
  5. Automator > File > New > Quick Action
  6. Add a Run AppleScript Action
  7. Enter the AppleScript below
  8. Save as Login Window
  9. Go to System Preferences > Keyboard > Shortcuts > Services > General
  10. Assign a keyboard shortcut to Login Window
tell application "System Events"
    tell its application process "ControlCenter"
        tell its menu bar 1
            click its menu bar item "User"
        end tell
        
        tell its window "Control Center"
            tell its group 1
                set btns to its buttons
                repeat with btn in btns
                    if name of btn = "Login Window..." then
                        click btn
                    end if
                end repeat
            end tell
        end tell
    end tell
end tell

The following AppleScript invokes Fast User Switching in Big Sur, assuming you enable Show in Menu Bar.

3
  • Can the script be modified to select a certain user? So if you had User1, User2, etc... Tell the script to go directly to User2 rather than to the Login Window?
    – You Me
    Mar 18, 2021 at 22:04
  • When trying to run this script, I get the following Syntax error: Can’t get window "Control Center" of application process "ControlCenter".
    – mach
    Jul 2, 2021 at 16:21
  • Is there any way to do it with Fast User Switching only showing in Control Center rather than the menu bar?
    – Barmar
    Aug 28, 2021 at 20:21
0

Yes you can - here's a modified script with user1 and user2 below - modify to match precisely your user names as they appear in the fast user switching menu.

You'll need a different script in THE OTHER user account to switch back - but this works beautifully and with an Apple Watch you only need to enter 1 of the 2 passwords.

tell application "System Events"
tell its application process "ControlCenter"
    tell its menu bar 1
        click its menu bar item "user1"
    end tell
    
    tell its window "Control Center"
        tell its group 1
            set btns to its buttons
            repeat with btn in btns
                if name of btn = "user2" then
                    click btn
                end if
            end repeat
        end tell
    end tell
end tell
end tell
1
  • When I try running this script, I get the following Syntax Error: Can’t get menu bar item "<my user1>" of menu bar 1 of application process "ControlCenter".
    – mach
    Jul 2, 2021 at 16:25

You must log in to answer this question.

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