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.
nothing worked for me. i tried like four diff things:
1. the power settings never sleep
2. caffeinate
3. deleting the pmset file
4. sudo systemsetup -setcomputersleep Never
i was suggested by mackeeper to reset my smc and pram but I am afraid it may corrupt my system or delete my super user settings for mysql, web server and other programming environments i installed. please help:
You should uninstall MacKeeper, it is probably causing your problem. It never helps anything. Reset SMC is no big deal, will lose power settings only.
i was having this problem before i installed mackeeper. what do you suggest to never sleep?
The StarMessage screensaver ( http://starmessagesoftware.com/moonscreensaver/ ) has also the option to keep the MAC awake for 2 hours, 8 hours, or permanenty.
This way of disabling the MAC sleep, is much easier than caffeinate.
What are the characteristics of “idle”. I want to establish whether my mac which I no longer have had idle turned off as I did mess around with the energy settings. If the MAC did not go into idle mode, then I believe that Garbage Collection may not have taken place (Non apple SSD, self installed without TRIM initiated).
This request has nothing to do with the present problem solution. However, my problem is with Google Mail. While composing my message in ‘Composition’ it is suddenly sent to “DRAFT” prematurely. How can I increase the lapse-time in order to avoid this troublesome problem ?
I am using Google Chrome version 40.0.2214.94 on OSX Yosemite version 10.10.2 .
Another problem. Please find me a way to increase the “FONT” size in my ‘CONTACTS’ list. My present font size is too small to read with any degree of ease. I would require a font size of at least 16.
My congratulations on all your past articles. Many have been of immense help. Keep up your excellent work !
No-one’s ever gonna answer that.
How can I increase the lapse-time in order to avoid this troublesome problem ?
Its not a glitch per se. This is happening as your Auto Save is enabled in Gmail. When u save ur msg without actually sending it, it is saved in the Draft mailbox. Same happens on Auto Save – it saves the current version of the mail [till that time]. So if u disable Auto Save then ur mail will not be saved and moved to the Draft folder till you physically save it. To increase the time before it auto saves, just increase the time settings.
just dont use chrome. it sucks
Is it better to not let your system sleep? How about checking the option of putting hard drive to sleep? When I close a laptop lid then the system sleeps anyway right?
I’ve heard different opinions on the effect of Sleep on a spinning hard drive.
If you need to do a lengthy download/install on a not so fast network you need the computer to be awake. I usually fire up terminal and type “caffeinate -d” which keeps it awake for a non determined period of time.
My 2014 non-retina iMac has no adjustment for initiating sleep, i.e., there is no control panel setting. It seems to sleep when it decides to, will these commands still work?