Help Me Keep My Mac Asleep

TL;DR: How can I most reliably determine whether I've logged in to my Mac?


Since updating from Catalina to Monterey my Mac won't stay asleep. I've spent hours on the phone to AppleCare and been through every troubleshooting step I can think of. I have a suspicion that it may be related to either my Caldigit TS3 Plus hub or the external drives attached to it, but I'm still uncertain. In the meantime, I thought perhaps KM could help me out...

I have a smart plug set to turn on with a KM Wake Trigger, and whenever my Mac wakes of its own accord, the plug has turned on. This tells me that KM runs its wake routine without requiring me to log in, so I figured perhaps I could do something like this:

  • Put my Mac to sleep again IF I don't log in within 20sec.

At least that would mean my Mac would be asleep most of the night. Any advice would be very welcome.

I had the same problem with my Macbook and Monterey. What works for me is "sleep" without power (just battery). Then it stays in sleep mode. :man_shrugging:

So you unplug the power every time you want to sleep your Mac?

My Mac is powered by the hub, so that would mean ejecting all my drives and unplugging the hub every time I want it to sleep. Not ideal.

Sorry, I don't know the English word. I used something like this. So everything can stay plugged in. But the power is gone. Ah, and yes so far that is the only solution I have found.

Yeah that wouldn't work for me but thanks for the suggestion. :+1:t3:

What I can add, since I am on 12.3.1, the problem occurs much less often. I'm not switching to 12.4 for now because I don't know if it's better or worse. Sorry, I do not know a solution either.

1 Like

Log in, or unlock? (Have I just asked a silly question? Is the KM Engine even running if there's no logged-in user?)

No, I'm the silly one; sorry for the misleading nomenclature. Yes, I'm logged in already, so it would actually be:

  • Put my Mac back to sleep IF it isn't unlocked within 20sec of waking.

In my case the mac reawakens by itself after a certain time. And I do not have a Caldigit TS3 Plus hub or external drives. This leads me to believe that it has to do with macos. Are you on 12.4?

Yup, 12.4. I did notice the problem didn't occur for a while when I disconnected the hub, but that may have been coincidence. I need to take the time to do a bit more testing.

Meanwhile, I just tried using the Unlock Trigger like this:

Re-Sleep Macro

Cancel Re-Sleep Macro

...but unfortunately it doesn't go back to sleep. :pensive:

Do you have a monitor that is connected directly via usb c? If so, what also works for me is to disconnect this monitor before "sleep".

That's interesting. I have two monitors:

Mac → Thunderbolt 3 to hub → HDMI → Monitor 1
Mac → USB-C to HDMI adapter → HDMI to DVI adapter → Monitor 2

This is good to know and might help me narrow down the cause of the issue. I'd like to find a solution that doesn't involve unplugging any hardware, but I'll have to see how I get on.

If you want, try disconnecting that. And see if your mac goes to sleep.

Perhaps a quick'n'dirty, then?

Do an image detect on the top-left corner of the main screen -- if there's an Apple logo then you've unlocked, if there isn't then put the computer back to sleep.

I'm assuming if you unlock it you then do something, not go straight to screensaver!

You've probably been through all this, but does the timestamp on your wake events not give you any clue as to what's causing it? Have you tried turning Power Nap off? Does this happen every night, or just occasionally?

I certainly will. It's just a pain to test as I have to leave it asleep for a few hours, meaning I can't use my mac.

Good shout. I actually tried that, as well as testing for the menu item "About This Mac", but neither triggered sleep.


Yeah. I don't even have a screensaver.

I've been through a lot of that stuff, and I couldn't find anything meaningful. I used:

log show --style syslog | fgrep "Wake reason"

Is that what you mean?

Yeah it's off and it's not just every night, but if I leave it sleeping for an hour, it will almost always wake.

Yes, I know. You don't even imagine all the things I've done to find the culprit. Take it easy. :slight_smile: And don't forget, if you just press this red button before you go to bed, you'll save electricity, money and help the climate.

1 Like

I've also added this to my wake routine, but it doesn't seem to help:

(Thanks for your previous help with getting a sudo script to work from KM, @Nige_S :pray:t3:)

I've just tried another code I found here. No idea whether it'll help.

sudo /usr/libexec/PlistBuddy -c "Add :ProgramArguments: string --no-multicast" \ 

Give this a go. I can take no credit, having shamelessly stolen the shell script...

Screen Locked Test.kmmacros (3.8 KB)


Yep, but then go the next step and use the timestamps from that to search for events around the wake events. Many can be disregarded -- waking up will result in a network event, a calendar sync, etc -- but you might see something that stands out.

Thanks mate. Looks promising, but I can't get it to work. Have you tested it yourself?

Oh, you mean cross-reference with recent events that aren't in the wake log? Smart! What's the best way to get a list of those?