Is it possible to prevent OSX from turning off displays when on the lockscreen? I'll lock my MBP with 2 external monitors, leave for 2-3 minutes, and come back and the monitor will be off. It then takes a bit of time for them to all come back on. I've tried Caffeine but it only appears to work when unlocked.
5 Answers
There is a free and open-source tool named KeepingYouAwake that can be used as per your requirements.
Having KeepingYouAwake activated will prevent the screen from turning off when lock screen mode is activated.
Download the latest version here.
or install it via cask:
brew install keepingyouawake --cask
This utility will not harm your Mac because it is based on an official command-line tool by Apple. BUT I cannot guarantee anything, so use this tool AT YOUR OWN RISK.
Settings > Power Management has the options that puts the display to sleep after some time.
It has two independent settings to be used if connected to a power source or using battery only.
Tweak these settings as per your requirement.
-
2These don't seem to apply to the lock/login screen. I have mine set to 1hr for both and the Mac still turns the display off minutes after locking (although it works correctly when leaving it unlocked)– nijaveCommented Sep 30, 2019 at 18:28
-
-
It's left at the default settings of starting after 20 minutes. It seems to work if I leave it unlocked but I've never seen it start on the lock screen– nijaveCommented Oct 2, 2019 at 13:22
Open Terminal and run the following:
caffeinate &
This will keep your display on until caffeinate
is killed (you can quit Terminal if you want).
To disable caffeinate
, run this in Terminal:
killall caffeinate
Hope this does the trick for you
I dug through Console and found it appeared to be checking for preventIdleDisplaySleep
boolean. Searching on Github I found HammerSpoon which has a module which can set this via lua scripting. I installed HammerSpoon and added this to ~/.hammerspoon/init.lua
and it prevented the sleeping issues
require "hs.caffeinate"
require "hs.hotkey"
hs.caffeinate.set("displayIdle", true, false)
hs.caffeinate.set("systemIdle", true, false)
hs.caffeinate.set("system", true, false)
hs.hotkey.bind({"cmd"}, "l", function()
hs.caffeinate.fastUserSwitch()
end)
(The hotkey bind to simulate Windows/Linux screen locking behavior)
The simplest solution without external software is use caffenaite:
caffeinate -d -w 1
Parameters:
-d Create an assertion to prevent the display from sleeping.
-w Waits for the process with the specified pid to exit. With pid 1 is waiting for main launchd process, which always exists.
If you do not want to run it manually use lauchd. Create file ~/Library/LaunchAgents/local.caffeinate.plist
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>local.caffeinate</string>
<key>ProgramArguments</key>
<array>
<string>sh</string>
<string>-c</string>
<!-- Prevent external display from sleeping. -->
<string>caffeinate -d -w 1</string>
</array>
<key>RunAtLoad</key>
<true/>
</dict>
</plist>