10

I run a MacBook Pro with OS X 10.11. I've noticed the machine hasn't slept well last night. There were events logged every couple of seconds in system.log throughout the entire night that the lid was closed.

I think it might be that two processes are preventing sleep while on A/C.

# pmset -g
System-wide power settings:
[...]
sleep                10 (sleep prevented by UserEventAgent, UserEventAgent)

Can I stop these processes (or any other process) from preventing sleep?

Dex
  • 121
  • Have you updated to OS X 10.11.6? – Graham Miln Aug 27 '16 at 10:55
  • What two processes do you think are preventing sleep? – Graham Miln Aug 27 '16 at 10:55
  • Yes 10.11.6 is installed. – Dex Aug 27 '16 at 11:09
  • UserEventAgent is running in two separate processes: one under normal user account, and the other under root. – Dex Aug 27 '16 at 11:09
  • 1
    What is the result of running pmset -g assertions? – Graham Miln Aug 27 '16 at 11:29
  • pmset -g assertions shows that everything (including PreventSystemSleep) is set to OFF (zero). The only value set to 1 in that output is UserIsActive. The last line from that output is: "Idle sleep preventers: IODisplayWrangler" but I'm guessing it's unrelated. – Dex Aug 27 '16 at 11:36
  • I'd recommend running EtreCheck on your Mac. Then posting the resulting report into a Gist. It's a bit too long to post here. And then updating your question with a link to the Gist. There are all kinds of plugins, launch daemons, etc, that could be causing this behaviour. – Alistair McMillan Aug 27 '16 at 11:41
  • Also, you mention that there are events logged every couple of seconds in the system log. Could you give us a sample of some of them? They might help point us in the right direction. – Alistair McMillan Aug 27 '16 at 11:43
  • The event I see most often is <date> <time> <hostname> airportd[60]: SecTaskLoadEntitlements failed error=22. This has been going on for the past few days, and it is thus unrelated to the problem with lack of sleep that started only yesterday. – Dex Aug 27 '16 at 12:23

5 Answers5

9

There are dozens of things that can prevent sleep built into macOS, and third party software can also disable sleep.

The first troubleshooting step is to run this command in Terminal:

pmset -g assertions

That will list the reasons your Mac is not currently asleep. Normally running on battery power you should get:

Assertion status system-wide:
   BackgroundTask                 0
   ApplePushServiceTask           0
   UserIsActive                   1
   PreventUserIdleDisplaySleep    0
   PreventSystemSleep             0
   ExternalMedia                  0
   PreventUserIdleSystemSleep     0
   NetworkClientActive            0

[further details removed for brevity]

Which means the only reason your mac isn't sleeping is due to user activity on the mouse/keyboard.

If you see something else (like PreventUserIdleSystemSleep) then your mac probably won't sleep at all and you should read the other details provided by pmset -g assertions to investigate further.

Abhi Beckert
  • 2,610
5

UserEventAgent suggests an input device was in active use. This may be a faulty mouse, keyboard, or other input device like a gamepad.

Try disconnecting all your externally connected devices and seeing if this behaviour continues.

Another cause may be a pet or vibrations causing a device to register movement.

Is Wake for network access enabled? See System Preferences > Energy Saver for this setting. Waking for network access will occasionally wake a sleeping Mac to examine and maintain the network environment.

Alternatively, consider using a third party tool to help put your Mac to sleep despite power assertions.

Graham Miln
  • 43,776
  • I don't have any input devices connected. BlueTooth is also off so there is no chance a neighbor's device is causing it. No pets either, and no vibrations (at least not possible to have had vibrations on the desk for 8 hours straight). – Dex Aug 27 '16 at 10:08
  • The setting "wake for wi-fi network access" is OFF. – Dex Aug 27 '16 at 11:12
1

In my case it was because I was running the iPhone emulator that comes with XCode. Closing the emulator down removed sleep prevented by UserEventAgent.

I only had one occurrence of UserEventAgent though. When I ran pmset -g I got this:

~$ pmset -g
System-wide power settings:
Currently in use:
 [...]
 sleep                10 (sleep prevented by UserEventAgent)
Enselic
  • 111
1

In my case the culprit was a Bluetooth keyboard with low batteries. Recharging the batteries fixed the problem.

Actually I got what I deserved because I ignored the "Keyboard batteries low" notifications for a week. My MacMini got so upset (they don't like being neglected) that she could not sleep... :-)

1

For anyone mildly interested in saving energy I created this function and saved it in my .bash_profile, then to sleep I just open up terminal and enter the sleepAndClose

function sleepAndClose {
  osascript -e 'quit app "SecuritySpy"'
  osascript -e 'quit app "VLC"'
  osascript -e 'quit app "qemu-system-x86_64"'
  pmset displaysleepnow
}
atreeon
  • 476
  • What does the script do? Why should I quit apps I don't have installed? Why is it useful? – ovichiro Aug 31 '21 at 05:58
  • pmset displaysleepnow tells the mac to sleep right now. Some apps always prevent sleep so I create a batch script to close them and then sleep. Here is an alternative that checks to see if the system can sleep https://apple.stackexchange.com/a/412715/324268 timemachine is a bit problematic as it can take a long time to close while it finishes writing the backup – atreeon Aug 31 '21 at 10:47
  • 2
    You should rather use SleepWatcher to detect sleeping and run $HOME/.sleep automatically, a script that you can populate as you wish. – Martin Braun Aug 18 '23 at 20:33