Is there an easy way to lock my mac and then immediately sleep, all in one command? I know I can show the login window and then choose the sleep button, but I'd prefer one step rather than two (and a wait in between). There's also the Lock Screen command in the Keychain menu, but that (stupidly) offers no sleep button that I can see. Could a script work for this, or would the script also get stuck after one command?

Update: Forgot to mention that I don't want to always have to enter my password after waking up from sleep, only after I explicitly lock the computer.

  • 3
    Locking implies password entry, what would be the benefit from locking otherwise? – nohillside May 7 '12 at 8:50
  • @patrix: Daniel L. updated my question, hopefully it's clearer now. – newenglander May 7 '12 at 11:15
  • What was wrong with the question? It's always nice to get a comment when getting a downvote, otherwise how can you learn from your mistakes? – newenglander May 9 '12 at 9:01

+ + will put the computer to sleep. Then, if you have "Require password [immediately] after sleep or screen saver begins" checked under System Preferences ➔ Security ➔ General, it will prompt you for a password when it wakes up.

  • Forgot to mention I don't want to enter my password after every wakeup from sleep, I'll update my post. – newenglander May 7 '12 at 8:15
  • 1
    @newenglander In that case, don't check the "Require password [immediately] after sleep or screen saver begins" - the first part of your question also explicitly states you want to "lock my mac" – binarybob May 7 '12 at 8:28
  • Sorry for the confusion, Daniel L. was kind enough to update my question, hopefully now it's clearer. – newenglander May 7 '12 at 11:15
  • The third key in that shortcut renders as unprintable for me in Chrome, for some reason. What is it supposed to be? – Dan J May 8 '12 at 20:42
  • @DanJ It's the eject key. Odd though, I'm using Chrome 18.0.1025.168 and Lion 10.7.3 and it looks fine here. – binarybob May 8 '12 at 21:10

Actually, a script containing these two commands (first one sleeps, second one suspends computer) worked fine:

osascript -e 'tell application "Finder" to sleep'
/System/Library/CoreServices/Menu\ Extras/User.menu/Contents/Resources/CGSession -suspend 

The order is apparently not important, neither command stops the other from completing.

Sorry for not making myself clear enough (Sometimes I want to put the computer to sleep without password prompt when waking).

You must log in to answer this question.

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