Mac OSX Terminal – Turn off system sleep

| | | |

If you use a Mac whether true server or a Mac Mini for a server this script below is very helpful to prevent the Mac from falling asleep and preventing the machine from being a server.

# Disable Computer Sleep
sudo systemsetup -setcomputersleep Off 
sudo systemsetup -getcomputersleep 

# Disable Computer Safe Sleep
sudo pmset -a hibernatemode 0
sudo nvram "use-nvramrc?"=false

# Remove Sleep Image
sudo rm /private/var/vm/sleepimage

If all of this still does not do it you can try to caffeinate your mac

caffeinate -t 144000 &

To re-enable sleep settings

# Enable Computer Sleep after 60 minutes
sudo systemsetup -setcomputersleep 60
sudo systemsetup -getcomputersleep 

# Enable Computer Safe Sleep
sudo pmset -a hibernatemode 3
sudo nvram "use-nvramrc?"=true

References:

All information on this site is shared with the intention to help. Before any source code or program is ran on a production (non-development) system it is suggested you test it and fully understand what it is doing not just what it appears it is doing. I accept no responsibility for any damage you may do with this code.