11

I’d like to assign an “Every Application” keyboard shortcut to bring up the login window, for when I step away from my computer. Is there a way to do this? (Lion-only methods are fine.)

3

9 Answers 9

4

I realise that this thread is probably quite old by now, but for all the options that has been given here, the simplest way has not been discussed.

Apple allows you to lock your screen with a keyboard shortcut. You don't have to create one, there is one built right in to OSX — via the “Require password after sleep or screensaver” feature.

Here is how to use it:

  1. Make sure that you have “Require password after sleep or screensaver begins” set to “immediately”.

To do this, follow these steps:

  1. Open System Preferences
  2. Click on Security (on Lion, “Security & Privacy”)
  3. Go to the General tab
  4. If you don't already have one, put a tick in the box next to "Require password after sleep or screen saver begins"
  5. Set the time interval to “immediately”
  6. Exit System Preferences

When now when you want to lock your Mac, simply use the keyboard shortcut

Ctrl ⌃ + Shift ⇧ + Eject ⏏ or Ctrl ⌃ + Shift ⇧ + Power

2
  • Not bad at all. Can be a bit sub-optimal if you’ve got Safe Sleep enabled and you want to unlock your machine soon after locking it, as it can still be writing the contents of your RAM to disk. Feb 28, 2012 at 7:23
  • Using Command ⌘+ Shift ⇧ + Eject ⏏ puts the Mac into sleep mode, which can achieve a similar goal Oct 16, 2022 at 8:59
7

If you want to assign alt ⌥+cmd ⌘+L to lock screen without installing any programs, in 5 minutes, I suggest you doing these three steps:

  1. Create a Service in Automator and set "Service receives selected" to "no input" instead of "text".

  2. (Still in Automator) add 'Run AppleScript' (search on the left "apple" then double-click).
    In the script in place of (* Your script goes here *) you copy-paste:

    do shell script "'/System/Library/CoreServices/Menu Extras/User.menu/Contents/Resources/CGSession' -suspend"
    Save and exit. (You can name your service "Lock Screen".)

  3. Open System Preferences, Keyboard then in Keyboard Shortcuts tab and under Services you will find your service "Lock Screen" towards the bottom of the list.
    Now, click on "none" next to "Lock Screen" to assign ⌥⌘ L to your service. Actually I suggest rather ⌃⌥⌘ L because ⌥⌘ L is assigned in Finder.

Done.

(For step 2 cudos goes to Lauri Ranta!)

2
4

Press Shift-Cmd+Q. Make sure that "Reopen windows when logging back in" is checked. Press enter.

Thanks to Lion, when you log back in, everything will look the same.

8
  • Not a bad workaround. I think it causes browser tabs to reload though, so not ideal if say you’re on a 3G internet connection. Jul 21, 2011 at 17:51
  • Yes it does cause everything to reload, which also may take some time depending how many apps you were running when you logged out. But then again other solutions require complex scripting setups, so this is as easy as it gets ;)
    – René
    Jul 21, 2011 at 19:36
  • Sure. Have you got any links to the alternatives? Jul 21, 2011 at 20:15
  • 1
    Scripting Fast User Switching comes to mind: superuser.com/questions/44433/…
    – René
    Jul 21, 2011 at 20:26
  • aha, excellent, cheers. Jul 25, 2011 at 13:30
4

Another way to log out to the fast user switching screen is to assign a shortcut to this shell command:

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

If you have the Alfred Powerpack, you can assign a shortcut to the lock action, but just typing "lock" doesn't take that much longer.

1
  • Just use this with a Automator Service and a shell script Action, Then assign a hotkey in the System prefs.
    – markhunte
    Feb 28, 2012 at 7:33
3

You can use Better Touch Tool (link) to create a multi-touch gesture or a shortcut to get to the login screen:

Multi-touch gesture

enter image description here

Keyboard Shortcut

enter image description here

2

You could also set an Applescript to click the "Login Window" menu item after a certain amount of time:

Login Window...

If you want to navigate the menubar, the script goes something like this:

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
1
  • Hi Davies! Did you manage to complete the script? Dec 17, 2012 at 8:09
1

This may not answer your question entirely, but at least it is a step in the right direction.

  1. Open Keychain Access located in the Utilities Folder inside the Applications Folder.
  2. Open Keychain Access preferences and check the box "Show keychain status in the menu bar." Check "Show keychain status in the menu bar"
  3. From the Lock icon in the menu bar, choose "Lock Screen."

From the Lock icon in the menu bar, choose "Lock Screen."

3
  • I have yet to find a way to assign a keyboard shortcut to the menu bar item and/or Keychain Access menu bar menu.
    – molle
    Jul 23, 2011 at 8:21
  • yeah, I think there is a way to get Shift-F7 to be a shortcut for assigning keyboard focus to the menu bar. If the keychain status icon is the leftmost icon in there, then it’s nearly a keyboard shortcut for the lock screen (i.e. Shift-F7, down arrow, enter). It’s a bit cumbersome though, and you have to keep the keychain status icon as the leftmost one in the menu bar. Jul 25, 2011 at 11:31
  • 1
    I'm writing on my phone right now, so I can't find it for you, but I know there are ways to AppleScript menu bar items. Maybe this can help? goo.gl/0peFU
    – molle
    Jul 25, 2011 at 13:23
1

Wow this has been going on a while… But after trying all these different suggestions I found the easiest way for me that I don't see mentioned here and elsewhere but is sorta common sense to me now that I think of it…

  1. Set the require password after sleep or screensaver to "immediately"
  2. Enable "hot corners" and select a corner to either "start screen saver" or "put display to sleep".

Then all you have to do is simply slide your cursor all the way into said corner and your screen saver will start of the display goes to sleep and then when you move the mouse again you will be at the login screen!

No scripts, no menu bar short cuts, no key sequences, just a simple swipe of the trackpad! This works wether you have the corner set to screen saver, sleep display, or close the lid.

1
  • Sure. That’s not a keyboard shortcut though. Oct 25, 2015 at 18:22
-1

There's only one way to do this, if you want to invoke the Login screen from a keyboard hotkey shortcut. It requires using the built-in Automator application in Mac OS. Here's the article on how to do it:

http://www.macyourself.com/2013/01/27/how-to-lock-your-mac-screen-with-a-keyboard-shortcut/comment-page-2/#comment-6991

2
  • 1
    In general, links don't make great answers (the website behind the link could disappear, the link could change, etc). Could you edit your answer to summarise the steps required?
    – John N
    Feb 13, 2017 at 10:03
  • 1
    “There's only one way to do this” — except there’s also this way to do it. Feb 13, 2017 at 14:35

You must log in to answer this question.

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