Fermata
Fermata copied to clipboard
Option to disable sleep only if on AC power?
I'm using a Mac with a KVM switch, and I'm trying to solve the problem of the mac going to sleep and dropping all my network connections when I switch away from it with the KVM. This happens because the KVM takes away the external display and the mac sees that it is closed with no external display and goes to sleep.
Fermata seems to work to solve this; I can point it at whatever app I have that I want to keep the network working for, and it can prevent sleep when the KVM switches away.
But I don't want to have to go and manually close Fermata or the app if I decide to unplug the machine from AC power and throw it in a bag. I would like a way to tell Fermata to stop and let the machine go to sleep if it sees that AC power has gone away.
Can this be added to Fermata? Or is there a nice way to script this with Automator or something?
Did you try sudo pmset -c disablesleep 1
? I thought that this worked at one time, but I'm not sure if it still does on Apple Silicon machines.
(Note: you may need to quit Fermata before trying the above.)
After investigating, I don't feel comfortable making this change for Fermata.
Here's the problem:
- Use either
pmset -a disablesleep 1
orIOPMSetSystemPowerSetting(kIOPMSleepDisabledKey, kCFBooleanTrue)
to disable sleep. - Close the lid.
- While the lid is closed, undo Step 1.
- Even though sleep is re-enabled and the lid is closed, the system will stay awake.
- The only way to sleep the system at this point is to wait an unknown amount of time (likely 5 seconds) and then force a sleep via
IOPMSleepSystem()
.
There's a lot of unknown heuristics happening in Step 4 and Step 5. These are likely to change in future versions of macOS. I can provide sample code (tested on Monterey) if you want to try compiling your own helper tool to do this. However, it's likely to break in the future.
I think you might find the built-in macOS setting to "Prevent automatic sleeping on power adapter when the display is off" useful. It can be found under Displays -> Advanced. You probably don't need Fermata for this at all?