Skip to content

Instantly share code, notes, and snippets.

@henrik242
Last active December 14, 2017 07:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save henrik242/77a373dd8dca35176873ee1e5eac4571 to your computer and use it in GitHub Desktop.
Save henrik242/77a373dd8dca35176873ee1e5eac4571 to your computer and use it in GitHub Desktop.
MacOSX hotkey for locking screen by starting screensaver

You can usually lock the screen by hitting ctrl-shift-power, but that will power down external monitors, which might take several boring seconds to start up again. Also, a MacBook with a TouchBar doesn't have the power button anymore. With the following guide you can lock the screen by starting the screensaver, keeping the monitors running.

Preparations

Set System Preferences » Security & Privacy » General » ✅ Require password immediately after sleep...

The simple way

  1. Download enable-screensaver.zip and unzip it to $HOME/Library/Services/

    (If you use OSX Sierra or older, use enable-screensaver-10.12.zip instead)

  2. Go to System Preferences » Keyboard » Shortcuts » Services » General » enable-screensaver.

  3. Choose a hotkey for it (I use ctrl-alt-cmd-k). You're good to go!

The difficult way

  • Start Automator, choose File » New and Service

  • Select that the Service receives no input in any application

  • Double click Library » Utilities » Run Shell Script

  • In the shell text field, add /System/Library/CoreServices/ScreenSaverEngine.app/Contents/MacOS/ScreenSaverEngine > /dev/null 2>&1 &

    (If you use OSX Sierra or older, use /System/Library/Frameworks/ScreenSaver.framework/Resources/ScreenSaverEngine.app/Contents/MacOS/ScreenSaverEngine instead)

  • Save the Service as enable-screensaver

  • Perform steps 2. and 3. above

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment