Take the 2-minute tour ×
Ask Different is a question and answer site for power users of Apple hardware and software. It's 100% free, no registration required.

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.)

share|improve this question
    
Related: apple.stackexchange.com/questions/11286/… –  ghoppe Jul 21 '11 at 17:27
2  
Common utilities like launchbar allow a quick keyboard shortcut to secure your session without actually logging out or having the screensaver be password protected. –  bmike Aug 15 '11 at 22:18
add comment

7 Answers

up vote 1 down vote accepted

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 ⏏

share|improve this answer
    
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. –  Paul D. Waite Feb 28 '12 at 7:23
add comment

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.

share|improve this answer
    
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. –  Paul D. Waite Jul 21 '11 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 '11 at 19:36
    
Sure. Have you got any links to the alternatives? –  Paul D. Waite Jul 21 '11 at 20:15
1  
Scripting Fast User Switching comes to mind: superuser.com/questions/44433/… –  René Jul 21 '11 at 20:26
    
aha, excellent, cheers. –  Paul D. Waite Jul 25 '11 at 13:30
show 2 more comments

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.

share|improve this answer
    
Just use this with a Automator Service and a shell script Action, Then assign a hotkey in the System prefs. –  markhunte Feb 28 '12 at 7:33
add comment

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
share|improve this answer
    
Hi Davies! Did you manage to complete the script? –  Barnabas Szabolcs Dec 17 '12 at 8:09
add comment

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

share|improve this answer
add comment

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."

share|improve this answer
    
I have yet to find a way to assign a keyboard shortcut to the menu bar item and/or Keychain Access menu bar menu. –  andersmoldin Jul 23 '11 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. –  Paul D. Waite Jul 25 '11 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 –  andersmoldin Jul 25 '11 at 13:23
add comment

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!)

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.