Keep computer running disable suspend
Long-running Terminal programs might not be detected by the operating system on a laptop or other device that has power-saving sleep or suspend modes. This can lead to disappointment as the long-running program hasn’t completed when the user checks back. This caffeinate Python script works with:
- Windows
- Linux systemd-inhibit
- macOS caffeinate
to keep the computer awake while a command line program is running, using features built into the operating system utilities.
To avoid a computer going to sleep / suspend in general persistently is OS-dependent.
macOS power management from Terminal
For macOS, check and save to a text file the current power management settings with pmset:
pmset -gTo disable sleep / standby while on AC power (charger), which is also suitable for fixed devices like the Mac Mini:
pmset -a sleep 0 standby 0Linux power management from Terminal
For Linux using systemd, check the current power management settings with:
systemctl list-unit-files | grep -E 'sleep|suspend|hibernate|hybrid'look for any that show “enabled”.
To disable sleep while on AC power (charger), which is also suitable for fixed devices like a desktop, use systemctl mask to disable the sleep, suspend, hibernate, and hybrid-sleep targets:
systemctl mask sleep.target suspend.target hibernate.target hybrid-sleep.targetWindows power management from Command Prompt
For Windows, check and save to a text file the current power management settings with powercfg:
powercfg /queryLook for “Current AC Power Setting Index” in the output for “Sleep” and “Hibernate” to see the current settings.
To disable sleep while on AC power (charger), which is also suitable for fixed devices like a desktop:
powercfg /change standby-timeout-ac 0To set Hibernate to never while on AC power (charger), while allowing hibernate to be enabled for battery power (important for laptop tucked away for the weekend), run the following command:
powercfg /change hibernate-timeout-ac 0Note that powercfg /hibernate off completely disables hibernate, which is not necessarily recommended for laptops that may be stored without power when not manually shut down each time.