Ignore "prevent sleep" request from a specific app

Your MacBook should always sleep when the lid is closed. If your Mac is not sleeping with the lid closed, this suggests a problem.

There are exceptions:

  • Some MacBooks can be plugged into external displays and, once connected, the MacBook's lid can be safely closed without triggering system wide sleep.

  • Previously it has been possible to install a third party kernel extension to override macOS's behaviour and stop sleep with the lid closed. Doing this carries risk and should be avoided.

Blocking Sleep

It is difficult for user space processes to block sleep. Sleep assertions should never block a user initiated sleep, either via closing the lid or requesting sleep from the Finder. Use pmset to view current power assertions:

pmset -g assertions

To manually initiate a sleep on the mac and override 'Preventing Sleep' applications run

pmset sleepnow

in the terminal

Edit

I agree, the Apple spec is flawed, Apple need to fix this!!!, there should definitely be a way to override the 'prevent sleep' system wide, however the above is the best workaround I've found...

...and if you want something that does a bit more checking (some apps I've discovered still prevent sleeping with the above command)

function slp2 {
  #add a list of programs here that you will always wish to close
  pkill -x qemu-system-i386
  pkill -x qemu-system-x86_64
  sleep 2
  assertion=$(pmset -g assertions | egrep 'PreventUserIdleSystemSleep');
  canSleep=${assertion:34:1};
  if [ $canSleep != "0" ]; then
    say "cannot sleep, please close offending applications"
  else
    pmset displaysleepnow
    say "goodnight, rest well"
  fi
}

You can also assign this to a Keyboard Maestro command so you don't need to open up a terminal and type in. Keyboard Maestro has an 'At system sleep' trigger (possibly there is some other commands, lid close maybe!) that may help further.


I sometimes have this issue with Spotify. An application can block sleeping even when laptop's lid is closed, ie by calling:

[[NSProcessInfo processInfo] beginActivityWithOptions:NSActivityUserInitiated reason:@"Good Reason"];

I suppose we shoudn't do that to prevent AppNap but the documentation is not very clear.