8

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?

9
  • Have you updated to OS X 10.11.6? Aug 27, 2016 at 10:55
  • What two processes do you think are preventing sleep? Aug 27, 2016 at 10:55
  • Yes 10.11.6 is installed.
    – Dex
    Aug 27, 2016 at 11:09
  • UserEventAgent is running in two separate processes: one under normal user account, and the other under root.
    – Dex
    Aug 27, 2016 at 11:09
  • 1
    What is the result of running pmset -g assertions? Aug 27, 2016 at 11:29

5 Answers 5

8

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.

4

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.

2
  • 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, 2016 at 10:08
  • The setting "wake for wi-fi network access" is OFF.
    – Dex
    Aug 27, 2016 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)
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
}
2
  • What does the script do? Why should I quit apps I don't have installed? Why is it useful?
    – ovichiro
    Aug 31, 2021 at 5: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 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, 2021 at 10:47

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .