One-Click Sleep with a Custom Keyboard Shortcut on macOS

2019/08/10

Introduction

One of the nicest things about using an MBP is being able to just close the lid and leave, then open it and get right back to work. But what about when you’re using an external monitor? I personally prefer hitting a keyboard shortcut to turn off the screen and walk away, then just pressing any key when I need it again. Thanks to macOS’s excellent sleep management, it wakes up almost instantly and I can jump straight back into work mode. Sure, there’s a Sleep button you can click, but how is that more convenient than a shortcut? Reference 1 links to a Zhihu discussion on this exact issue, and honestly, even with hundreds of answers, there still wasn’t a truly practical solution.

Below are the four methods I’ve summarized for putting your Mac to sleep with a keyboard shortcut.

Tutorial

Method 1 - Use the built-in system lock shortcut

First, macOS provides a built-in shortcut for locking the screen: ctrl+comd+Q

image-20201011164249647

It’s similar to Win + L on Windows. After pressing it, the screen locks immediately, and a few seconds later the Mac goes to sleep automatically. However, since this shortcut is provided by the system, it can’t be customized. Also, the screen doesn’t go black right away after locking — there’s a few-second period where it stays lit. Personally, I’m not used to that approach. And honestly, if Apple gives us a shortcut for Lock Screen, why not provide one for Sleep in the same menu?

Method 2 - Use a special keyboard

If you’re using a Magic Keyboard or an older MBP, you may find the circled 3 key on the keyboard (the eject key). As shown in the image, you can use the shortcut ctrl+comd+eject to put the Mac to sleep. In reality, though, not all keyboards have this key, so this only works if your hardware supports it. Still, it’s pretty convenient.

image-20201011162357934

Method 3 - Use third-party software

You can also achieve this with third-party software. A more complicated option is the BAB app mentioned in Reference 2. Its keyboard module lets you configure one-key sleep, but the software is so powerful that it can do far more than just sleep — it can trigger all kinds of system actions. That also makes it very easy to conflict with other software, so after using it for a while, I gave it up because I couldn’t tolerate the side effects from those conflicts. image-20201011182220164

A simpler option is an app called QuickSleep (the download link from PC6 is provided in Reference 3). The whole app does just one thing: lock the screen. You can assign any shortcut you want, and it’s very straightforward.

image-20201011182327162

I used to love tinkering and downloading all kinds of software, but after overdoing it, my system would constantly run into weird issues. Later I realized the problem was software conflicts. These days, if I can achieve something without third-party tools, I’ll avoid them whenever possible. Automator is a built-in macOS tool for running scripts, so there’s nothing to download. The idea is simple: since macOS can run shell scripts, we can use Automator to execute a sleep script we write ourselves. It’s incredibly simple — just one line of code. Here are the steps:

  • Search for Automator in Spotlight and open it. image-20201011183821301

  • In the popup window, choose Quick Action and click Choose. image-20201011183936701

  • In the next window, follow the image and select Utilities → Run Shell Script. Make sure the Workflow receives option marked as 3 is set to no input, then enter the following code in the area marked as 4 and click Save (if you just close the window, it will prompt you to save).

    Select Run Shell Script under Utilities in Automator

    pmset sleepnow
    

    image-20201011184713686

  • Open System Preferences → Keyboard Shortcuts → Services, then find the script you just named (it’s usually under General, and it’s definitely there — just look carefully).

    image-20201011185015435

  • Once you find it, assign a shortcut that doesn’t conflict with any system shortcut, and you’re done. image-20201011185152126

Give it a try — it works really well, and you don’t need any third-party tools. I personally got used to using ctrl+commd+L to turn off the screen. What about you?

References

  1. Zhihu - How can I lock the screen in macOS with a keyboard shortcut?
  2. BAB Official Website
  3. PC6 - QuickSleep Download

All articles in this blog, unless otherwise stated, are licensed under @Oreoft . Please indicate the source when reprinting!

Table of Contents