Closed iamfredrik closed 11 months ago
There is a setting for 1., is it enabled? The sleep button in the Apple menu is not greyed out?
Yes, the setting "Prevent your Mac from sleeping when the power adapter is disabled" is checked. The sleep button in Apple menu is not greyed out.
Okay, I can understand the behavior when requesting charge to max, but shouldn't it be unregulated when requesting charge to full, i.e. enabling default MacOS settings?
I tried to reproduce it a few times, but it consistently works for me. What happens when you disable the power adapter and then toggle the setting in the GUI once and twice?
Well, yes, that could be a sort of micro-optimization, but so far I considered it unnecessary internal complexity. I don't think there is any noticeable impact on power draw by not sleeping. Maybe the drawbacks of disabled sleep are worth avoiding, not sure.
The sleep button does in fact get greyed out now after a MacOS update and restart. However, in clamshell mode I'm still having the problem that the system goes to sleep despite this and then I have to open the lid to get it to wake up. So I have to use a Keep Awake feature of a third party app to prevent this (or do it manually using terminal). Here's how to correctly disable sleep manually using the terminal so that it doesn't go to sleep in clamshell mode:
sudo pmset -a sleep 0 sudo pmset -a hibernatemode 0 sudo pmset -a disablesleep 1
sudo pmset -a sleep 1 sudo pmset -a hibernatemode 3 sudo pmset -a disablesleep 0
Fun. Currently, only the last command is executed. I’ll have to experiment with this some day, but I’m busy with work right now, sorry. :(
I dealt a bit with disabled sleep as part of issue #3 and I cannot reproduce the issue, the system stays awake perfectly fine. Sometimes it goes to sleep immediately when sleep is re-enabled (as part of enabling the power adapter), but that is a macOS bug that has been discussed online various times (and does not affect Intel Macs, for example). As for your commands:
sudo pmset -a sleep 0
According to the documentation I read, this should disable automatic sleeping based on a timer. I do not think it should be relevant here.
sudo pmset -a hibernatemode 3
This is more of an instruction on what to do when sleeping rather than specifying whether to sleep.
sudo pmset -a disablesleep 0
This is currently executed (well, not really because the tool uses the IOPM APIs directly, but it should replicate the behavior).
Of course, the first two might somehow influence the bug I mentioned, if that is what you hit. Can you please explain what the additional commands are supposed to achieve precisely and maybe give reproducible steps to compare their behavior?
The command "sudo pmset -a sleep 0" on a Mac sets the system sleep timer to 0 minutes, effectively disabling automatic sleep.
The command "sudo pmset -a hibernatemode 0" on a Mac sets the hibernation mode to 0, which disables hibernation. The default value is 3 which means the system will store the contents of memory to disk and then go into a low-power mode.
The command "sudo pmset -a disablesleep 1" on a Mac enables the option to disable sleep. This means that sleep is now disabled.
All the above commands are required when using Battery-toolkit in clamshell mode using a Macbook Air M2. Otherwise the system will go to sleep and it won't wake unless opening the lid, which is very annoying when using a vertical stand.
Well, you basically repeated what I described. I do not understand why the hibernation mode matters at all in this scenario. Neither do I understand why automatic sleep with a timer would trigger when sleep is globally disabled. Also I need steps to reproduce the exact issue (do you wait some time till the sleep timer triggers?), because just disabling the power adapter keeps the machine awake with the lid closed.
Those commands have been suggested all over the internet to keep Macs awake. There are utility apps like Amphetamine that does the same thing. Macbooks go to sleep in clamshell mode even when sleep is disabled, because they are not designed to operate in clamshell mode using battery power.
Steps to reproduce.
I finally reproduced the issue. I'm afraid this is an extension of the Apple bug I mentioned previously. Namely, once the display(!) goes to sleep, it indeed does not wake without opening the lid. And when you open the lid and then close it again, it appears to cache the usual sleep request. When you re-enable the power adapter afterwards (and thus re-enable sleep), the system will immediately sleep, even without any acute reason for doing so. I confirmed the system indeed does not sleep when triggering the display sleep issue by playing music till reaching display sleep. The keyboard remained lit, the music kept playing, but the system would not wake the external monitor till opening the lid.
While I understand this is annoying for you, I will not address this as part of this tool. The only concern with toggling the power adapter is system-wide sleep to enable usability in clamshell mode when the power adapter is disabled. I do not want to introduce workarounds with unexpected behavior (disabling display sleep) to work around Apple bugs that may be fixed in the future.
EDIT: Hmm. In fact, your Terminal commands make no difference whatsoever for me, the behavior is still "broken". Would have been surprised if "hibernatemode" or "sleep" made a difference anyway. Weird though it seems to work for you, I'd expect you need to adjust "displaysleep".
Fair enough. The best bet for now is to use the Amphetamine app and set a custom trigger to disable sleep when the power adapter is disabled.
Hello,
I truly appreciate the effort you put into this project. However, I wanted to bring to your attention some issues I have encountered while using this application.
Sleep is not disabled when disabling the Power Adapter
Sleep gets disabled when requesting charging to max/full
Expected behavior would be the reverse of the above.
Environment:
MacBook Air M2 MacOS Ventura 13.5.2
Thank you!