Skip to content

Instantly share code, notes, and snippets.

@pwnsdx pwnsdx/nosleep.sh
Last active Sep 14, 2019

Embed
What would you like to do?
Completely disable sleep on any Mac
# Useful to prevent Macbooks to go to sleep when closing the lid instead of running tools that requires a Kernel Extension (e.g. InsomniaX) and more
# Before doing anything, save your current configuration using
pmset -g
# To disable sleep
sudo pmset -a sleep 0; sudo pmset -a hibernatemode 0; sudo pmset -a disablesleep 1;
# And to go back to normal
sudo pmset -a sleep 1; sudo pmset -a hibernatemode [original hibernatemode value]; sudo pmset -a disablesleep 0;
@ghost

This comment has been minimized.

Copy link

commented Jan 26, 2019

Hey! Do you know how to go back to normal after running the command? Thank You!

@Moarram

This comment has been minimized.

Copy link

commented Feb 1, 2019

Hey! Do you know how to go back to normal after running the command? Thank You!

Run all the same commands but switch the 1's and 0's like this: sudo pmset -a sleep 1; sudo pmset -a hibernatemode 1; sudo pmset -a disablesleep 0;

@pwnsdx

This comment has been minimized.

Copy link
Owner Author

commented Feb 4, 2019

Hey! Do you know how to go back to normal after running the command? Thank You!

Run all the same commands but switch the 1's and 0's like this: sudo pmset -a sleep 1; sudo pmset -a hibernatemode 1; sudo pmset -a disablesleep 0;

This is correct except for hibernatemode which should be 25 (the defaults, I believe). So the full command should be: sudo pmset -a sleep 1; sudo pmset -a hibernatemode 25; sudo pmset -a disablesleep 0;. I also updated the gist to reflect that. Thanks for asking how to revert.

@jujulienarc

This comment has been minimized.

Copy link

commented Apr 10, 2019

be carful sudo pmset -a hibernatemode 25; should be use for desktop and not macbook. for portable the default is sudo pmset -a hibernatemode 3; you can check the reference with man pmset .

@laurion

This comment has been minimized.

Copy link

commented Apr 13, 2019

@pkhetrapal

This comment has been minimized.

Copy link

commented May 11, 2019

I think only sudo pmset -a disablesleep 1 should do the trick.

@kallenp

This comment has been minimized.

Copy link

commented May 13, 2019

Howto make this permanent ?

@pkhetrapal

This comment has been minimized.

Copy link

commented May 13, 2019

as in?

@kallenp

This comment has been minimized.

Copy link

commented May 13, 2019

yes, I am need to make this change permanent. What is the best way ?

@pkhetrapal

This comment has been minimized.

Copy link

commented May 13, 2019

Just run the above command once - it will disable sleep permanently. To revert your change just run sudo pmset -a disablesleep 0 again

@kallenp

This comment has been minimized.

Copy link

commented May 13, 2019

OK.
I will try it tommorrow morning.

Thanks man !

@conradogarciaberrotaran

This comment has been minimized.

Copy link

commented May 13, 2019

Ok @kallennp, tell us how it was.

@PianoMan2112

This comment has been minimized.

Copy link

commented May 19, 2019

I have some concerns about this, especially the hibernatemode 25 undo command. On my MacBook Pro (Retina, 15-inch, Mid 2015) running macOS Mojave version 10.14.4 with Turn display off after: set to 1 hr, pmset -g returns:

System-wide power settings:
Currently in use:
sleep 60
hibernatemode 3

with no mention of disablesleep. Neither these results, or the output of man pmset, mention disablesleep anywhere, although I have read ( [https://www.reddit.com/r/macbook/comments/alz13m/how_to_entirely_disable_sleep_on_a_macbook/] ) that sudo pmset disablesleep 1 does work, and doesn't need any other parameters, which makes sense since sleep and hibernation are irrelevant if sleep is disabled. (I'm not brave enough to try it, being that I can't see its status in the pmset -g output, even with pmset -g everything).

man pmset shows this for hibernatemode, which makes it look like 25 will be slower than the default setting of 3:

hibernatemode = 0 by default on desktops. The system will not back memory up to persistent storage. The system must wake from the contents of memory; the system will lose context on power loss. This is, historically, plain old sleep.

hibernatemode = 3 by default on portables. The system will store a copy of memory to persistent storage (the disk), and will power memory during sleep. The system will wake from memory, unless a power loss forces it to restore from hibernate image.

hibernatemode = 25 is only settable via pmset. The system will store a copy of memory to persistent storage (the disk), and will remove power to memory. The system will restore from disk image. If you want "hibernation" - slower sleeps, slower wakes, and better battery life, you should use this setting.

(Sleep can be set to 0 in System Preferences, Energy Saver, Power Adapter, and select Prevent computer from sleeping automatically when the display is off, and optionally deselect Put hard disks to sleep when possible to change disksleep from 10 to 0.)

@EveryMac

This comment has been minimized.

Copy link

commented Jul 21, 2019

be carful sudo pmset -a hibernatemode 25; should be used for desktop and not MacBook. for portable the default is sudo pmset -a hibernatemode 3; you can check the reference with man pmset .

The newer MacBook Pro has M.2 fast memory access, so the speed is greatly improved enough to use "25"

hibernatemode 25 is CORRECT, especially for newer MacBook Pro [post-2005]
https://www.lifewire.com/change-mac-sleep-settings-2260804 [check it out]

@adah1972

This comment has been minimized.

Copy link

commented Sep 13, 2019

hibernatemode 25 is not the default. I verified this after Restore to Default in Energy Saver. The article @EveryMac mentioned did not state that 25 was the default—actually, it just can be used on newer laptops (not useable on earlier models):

Note: Since 2005, the default sleep mode for portables has been Safe Sleep, but not all Apple portables support it. Apple says that models from 2005 and later directly support Safe Sleep mode. Some, but not all, earlier versions of Mac hardware include the feature.

@adah1972

This comment has been minimized.

Copy link

commented Sep 13, 2019

Re-reading the article, it is actually a bit vague and confusing about mode 25. This said, the default is definitely not 25. Mine is changed to 25 by a tool recently, and I am very unhappy about the new behaviour. This is partly the reason how I got here.

@pwnsdx

This comment has been minimized.

Copy link
Owner Author

commented Sep 14, 2019

Hi everyone, I updated the gist. I think it's best to get the current pmset configuration using pmset -g and use the values from there to go back to normal.

On a MacBook, the default power settings are:

% pmset -g
System-wide power settings:
Currently in use:
 lidwake              1
 autopoweroff         1
 standbydelayhigh     86400
 autopoweroffdelay    28800
 standbydelaylow      10800
 standby              0
 proximitywake        1
 ttyskeepawake        1
 hibernatemode        3
 powernap             1
 gpuswitch            2
 hibernatefile        /var/vm/sleepimage
 highstandbythreshold 50
 womp                 1
 displaysleep         10
 networkoversleep     0
 sleep                1
 acwake               0
 halfdim              1
 disksleep            10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.