Apple - Keyboard shortcut to sleep a Mac

If others do have a keyboard with an eject key, you can just press Command ⌘+Option ⌥+Eject ⏏.

Other shortcuts:

Control ^+Shift ⇧+Eject ⏏ - Put displays to sleep
Command ⌘+Control ^+Eject ⏏ - Restart
Command ⌘+Control ^+Option ⌥+Eject ⏏ - Shut down

If others like the OP have a MacBook Air or a MacBook Pro with a power key in place of an eject key, substituting the power key for eject should work in Mountain Lion and later versions of OS X, but not in Lion.

Since Mavericks, another option is to just press the power button or power key. It now puts a Mac to sleep instead of showing a dialog with different options.

If you don't have a keyboard with an eject or power key, you can use a private.xml like this with KeyRemap4MacBook:

<?xml version="1.0"?>
<root>
  <item>
    <name>test</name>
    <identifier>test</identifier>
    <autogen>__KeyToKey__ KeyCode::S, VK_CONTROL, VK_OPTION, VK_COMMAND | ModifierFlag::NONE, KeyCode::VK_CONSUMERKEY_EJECT, ModifierFlag::OPTION_L | ModifierFlag::COMMAND_L</autogen>
 </item>
</root>

Or create a workflow like this in Alfred:


You can assign any unused key combination (like fnF12) using System Preferences » Keyboard » Keyboard Shortcuts » Application Shortcuts Click the + button, then under Application, leave All Applications, under Menu Title enter Sleep, and under Keyboard Shortcut, press fnF12.

Note: For the step "under Menu Title enter Sleep", the Sleep is according to your language. For example, under Traditional Chinese, you should enter 睡眠.

enter image description here

Another option, if you're more Terminal-inclined:

  • space
  • Type Terminal
  • push Enter
  • Type sudo shutdown -s now

Press the power button. Assuming you haven't reconfigured its behaviour, it should pop up a dialog with options to Sleep, Restart, or Shutdown the laptop. The "Reopen windows when logging back in" checkbox has keyboard focus by default; hitting the Tab key twice will put focus on the Sleep button - hitting the Space bar will then put the MacBook Air to sleep.

(Note that hitting Return will activate the dialog's default action - namely, to shut the computer down.)

Not as quick as a single keyboard shortcut, but faster than the mouse and without closing the lid. :)