1

Is there any keyboard shortcut to go here?

enter image description 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.

enter image description here

2 Answers2

0

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.

user3439894
  • 58,676
-1

You will find the user accounts system preference pane here on OS X 10.11 (El Capitan): Press cmdshift+ G in Finder, and paste the following path:

 /System/Library/PreferencePanes/

The one you´re looking for is called "Accounts.prefPane". To make it real easy to access by keyboard shortcut, you can start Automator, click "New" and choose "Service". Set it to "not receive data from a application", and add the Automator action "Open Finder objects" from the "Files and folders" category. From there, browse to the path I described above and choose the "Accounts" prefpane.

Save the service, and go to System Preferences -> Keyboard. Select "shortcuts", and choose "Services". From the list on the right, scroll until you see the name of the service you just made. Select it, and click in the right field to assign a new shortcut.

Run the service once from the Finder->Services menu, and now you have just made yourself a keyboard shortcut to the user accounts area in OS X. Voilá.

You can of course also make an alias to that one, or any of the other prefpanes - and even drag it to the Finder toolbar for quick access, quite handy.

Andreas
  • 11
  • This answer doesn't address the question. It's about getting to Login Window and not about opening the user prefpane. – klanomath Jun 25 '16 at 12:43