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.

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.

share|improve this question
3  
Locking implies password entry, what would be the benefit from locking otherwise? –  patrix 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
add comment

2 Answers

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

share|improve this answer
    
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
add comment
up vote 2 down vote accepted

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

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.