Set or Disable Sleep Due to Mac System Inactivity from Command Line in Mac OS X
Mac users can adjust the idle time to sleep their computers easily through the Energy Saver preference panel, but many advanced Mac OS X users may wish to turn to the command line to perform such a task. This allows for scripting, remote checking and changing idle sleep behavior through SSH, and you can also use it to set the idle time requirements beyond what is allowed through the standard System Preference approach.
Note this is not actually initiating sleep from the command line, but rather making changes to sleep behavior, like whether the Mac will sleep at all or not, and how long the inactivity period would be before the computer starts sleeping.
To get started, launch Terminal from the /Applications/Utilities/ folder and use any of the following command strings. Sudo is also required, so expect to enter an administrator password to set any changes to sleep idle behavior.
How to Set Mac System Sleep Idle Time from the Command Line
You can set the amount of idle time in minutes that need to elapse before a Mac goes to sleep with the following syntax, in this example we’ll use 60 meaning an hour of inactivity before the Mac sleeps:
sudo systemsetup -setcomputersleep 60
Replace 60 with any other number in minutes if desired.
How to Turn Off System Sleep from the Command Line in Mac OS X
You can also completely disable system sleep due to inactivity from the command line with the same command, replacing the number with “Never” to indicate the Mac won’t ever sleep from inactivity:
sudo systemsetup -setcomputersleep Never
You can also use “Off” instead of “Never”, though pay attention to casing when using the terminal commands.
How to Check Current Mac System Sleep Status
If you want to determine what the current system sleep behavior is set to, you can use the -getcomputersleep flag:
sudo systemsetup -getcomputersleep
If you see a number reported back, it’s the number in idle minutes to determine when the sleep event occurs, thus indicating the sleep function is on. Similarly, if what you see reported is “Never” then the Mac will not sleep from inactivity.
If you have any other similar tips, tricks, or interesting info about sleeping a Mac or adjusting sleep behavior from the command line, share with us in the comments below.