Any shortcut to go to user account window? Is there any keyboard shortcut to go here?



EDIT: This script does not work

on run {input, parameters}

    (* Login menu has to be the last! *)

  tell application "System Events"
    tell process "SystemUIServer"
      set n to number of menu bar items of menu bar 1
      tell menu bar item n of menu bar 1
        click
        repeat with i from 1 to 10
          try
            if name of menu item i of front menu contains "Login Window" then
              click menu item i of front menu
              exit repeat
            end if
          end try
        end repeat
      end tell
    end tell
  end tell

  return input
end run


EDIT2: I made this Automator Script (when I execute it, it works) but when I try to assign it a keyboard shortcut it does not work.
If you are trying to bring up the Login Window via a keyboard shortcut the answer is, there is not a default keyboard shortcut to invoke the Login Window. However one can create an Automator Service which can then have a keyboard shortcut assigned to it.

The problem with that method is finding a globally responsive keyboard shortcut that will trigger without interference and work consistently regardless of what has focus when the keyboard short is triggered. In some cases it may be advantageous to use a third-party app, e.g Karabiner, to accomplish the task.

What I'm presenting here is a command that can be executed, a number of different ways, and incorporated into an Automator Service and or an AppleScript Application, etc.

As an Automator Service, all that is required is adding a Run Shell Script Action with the command. You might also be able to use the command in conjunction with a third-party app that can be triggered by a keyboard shortcut.

Personally, whenever applicable, I like to use an AppleScript Application because I can trigger it using Spotlight or place it on the Dock, etc. It may be a few extra keystrokes however for me it just works better and I avoid what can be problematic with trying to assign an Automator Service a global keyboard shortcut. 

The command that will invoke the Login Window is:

As a Terminal command and or a Run Shell Script Action in Automator:

/System/Library/CoreServices/Menu\ Extras/User.menu/Contents/Resources/CGSession -suspend


In AppleScript the command is:

do shell script "/System/Library/CoreServices/Menu\\ Extras/User.menu/Contents/Resources/CGSession -suspend"


If you'd like to switch directly to a different user you can use the following command as an example.

As a Terminal command and or a Run Shell Script Action in Automator:

/System/Library/CoreServices/Menu\ Extras/User.menu/Contents/Resources/CGSession -switchToUserID 502


In AppleScript the command is:

do shell script "/System/Library/CoreServices/Menu\\ Extras/User.menu/Contents/Resources/CGSession -switchToUserID 502"


My primary login User ID ($UID) is 501 and I have a Test Account which has a $UID of 502. So the above command enables me to invoke Fast User Switching to my Test Account using Spotlight (Command-Space) and the AppleScript app named TA.app. It is the top hit in Spotlight so if I type Command-Space-T-A-Enter I get my Test Account Login Window quickly and easily.

So with the commands provided, you should be able to utilize what's appropriate to your needs/wants to code with in a much easier way then the code you've shown in your question.

Note: Make note of the double-backslash in the AppleScript do shell script command line to escape the space in the shell command line vs. the single-backslash as a normal command in Terminal.