Skip to content

Immediate sleep after waking #33

@nihaals

Description

@nihaals

Sometimes after waking up my M1 MacBook Pro with a monitor always connected, my laptop goes back to sleep a couple seconds after waking and unlocking. I then have to unlock again.

I added some logs and it seems to be hitting

pmset sleepnow
during this. I have mine running every 10 seconds and it took a few times to intentionally reproduce so the cause might be the script running during wake when the other monitor is still turning on/connecting.

Maybe there's a way to track time since last wake and if it's less than ~10 seconds then ignore it? I can also try logging more values to help find a way to differentiate/find the root cause if there's any more useful context I can gather.

One idea of a cause is that ioreg -r -k AppleClamshellState | grep AppleClamshellState | grep Yes takes ~25ms and all the pmset commands take ~750ms, so if the script runs during sleep, sees the lid is closed and then during the 750ms of pmset -g powerstate | grep AppleDisplay | grep USEABLE (or maybe even the following commands, I'm not sure what DCPDPDeviceProxy and DCPDPServiceProxy represent) running the lid is opened and the system wakes up, it looks like the lid is closed and the system is awake, so we go to sleep.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions