OSX Tips – Turn off sleep mode from the command line

If you’ve ever needed to turn off sleep mode in Mac OSX 10.8 (Mountain Lion) from the command line, here’s how you do it:

sudo pmset sleep 0

To turn it back on again, use the following:

sudo pmset sleep 15

If you wanted to save the original value you could do something like this:



# get current energy saver timeout
CURRENT_TIMEOUT=$(sudo pmset -g | awk '$1=="sleep" {print $2}')

# save current timeout value to disk

sudo pmset sleep 0

You could then turn it back on with something like this:



# get old energy saver timeout value if available

OLD_TIMEOUT=$(cat $FILENAME 2>/dev/null)

if [ "$OLD_TIMEOUT" ]; then
   echo "Old Value = '$OLD_TIMEOUT'"
   echo "No old value found, using 15"

# set timeout
sudo pmset sleep $OLD_TIMEOUT

The scripts above will find the current sleep timeout setting, save it to a file on disk, and then try to use that value to set it back to its original value when re-enabling sleep. If it can’t find that file it will just use the default value of 15 minutes.


You can also turn off display sleep with:

sudo pmset displaysleep 0

and disable hard disk sleep with:

sudo pmset disksleep 0

You can then re-enable them with the following:

sudo pmset disksleep 180
sudo pmset displaysleep 15

This post is part of a series related to optimising osx from the command line. Next up is turning off WiFi/Airport from the command line.

Share Button

One thought on “OSX Tips – Turn off sleep mode from the command line

  1. Pingback: OSX Tips – Turn off WiFi from the command line | DGKApps – Blog

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>