Hibernation Tool for Mac OS

Hibernate Since quite some time Mac OS also has a hibernation mode, also known as suspend-to-disk. But as usual for Mac, you cannot select it by hand. In fact, a suspend-to-ram always does a suspend-to-disk as well, so that in a case of power loss (like empty battery) you can start the computer from the image on the hard disk without losing anything. Apple calls this suspend combination “Safe-Sleep“.

So far so nice. But sometimes you might want to go directly into hibernation mode. Therefore I wrote a little applescript, which in respect to similar scripts doesn’t need any administrator rights to work. In fact the icon was the most difficult part.

Download it right here.

For an easy access to the hibernation mode, you either move it to /Applications/ or somewhere else and drag it into your dock, or you put it in ~/Library/Scripts and activate the script menu with the Applescript Utility.

PS.: If your Mac does not support the hibernation mode, there is a chance that you can enable it. Look here.

PPS.: As a Mac OS X user you might also be interested in another tool by me: UpdateCheckΒ (Software Update Notifications for Non-Admin-Users)

Troubleshooting:Β if you experience that your computer still goes into normal sleep mode, open Hibernate.app/Contents/Resources/Scripts/main.scpt and increase the delay to 30 at the end of the script.

33 thoughts on “Hibernation Tool for Mac OS

  1. Pingback: Ralf's Blog

  2. Exactly what i needed, great work πŸ˜‰

    As i’m used to have the Dashboard turned off for performance improvements i needed the “Deep Sleep”-Widget as App-Solution – got it πŸ˜‰

  3. Thank you – this is exactly what I have been looking for. There are a couple of apps out there that are far too clever, all I’ve wanted was something that would let me hibernate the computer at the end of the day without interfering with the MacBook’s usual sleep mode which is really quick and effective. This is perfect. Many thanks.

  4. this is great–please continue to update it. i think hibernation is more energy efficient, and thus much better for the environment, than normal sleep. (perhaps apple likes selling batteries more than saving the world?) i would love the option to turn off the confirmation dialog, however, to make it quicker. it’s just an extra step i don’t need, since the worst result of a mistaken double-click is 30 lost seconds. danke!

  5. @matt: you can easily change that on your own. Just open Hibernate.app with the “Script Editor.app” and add a -- to the beginning of the line display dialog ("Do you want to hibernate?" &...

  6. Hello,
    thank you for sharing this very useful app. I think though, that it doesn’t save the ram where the safe sleep saves it, but on a different location instead. Since I got 4 gigs of ram, safe sleep takes 4 gigs, and I think now that I ran hibernate.app it takes another 4 gigs.
    If I’m right, may I ask where it saves them so I can delete them manually?
    Thanks

  7. @Orestis: The tool doesn’t decide were to save the memory. It just tells the system to go into hibernation. Everything else is done by Mac OS, so I have no idea why there should be a difference. And to be honest, I don’t believe it, you are probably seeing something else.

  8. @Tom: The man page of pmset doesn’t say anything about hibernatemode 5, so I have no idea what that mode is. But if you know, what you do, you can just drag the Hibernation.app on the Script Editor and change the value in line do shell script "/usr/bin/pmset force -a hibernatemode 1"

  9. Thanks, that worked great. Mode 5 is the same as 1 except for use with secure memory setting on newer macs.

    From a macworld article:


    # 0 – Old style sleep mode, with RAM powered on while sleeping, safe sleep disabled, and super-fast wake.
    # 1 – Hibernation mode, with RAM contents written to disk, system totally shut down while β€œsleeping,” and slower wake up, due to reading the contents of RAM off the hard drive.
    # 3 – The default mode on machines introduced since about fall 2005. RAM is powered on while sleeping, but RAM contents are also written to disk before sleeping. In the event of total power loss, the system enters hibernation mode automatically.
    # 5 – This is the same as mode 1, but it’s for those using secure virtual memory (in System Preferences -> Security).
    # 7 – This is the same as mode 3, but it’s for those using secure virtual memory.”

  10. @Tom: I think this information is not accurate. I remember modes 5 and 7 were mentioned in older man pages of pmset, but Apple removed it with a reason I assume. Just read section “A Question of Encryption” in this article: http://db.tidbits.com/article/9115

    I quote: “Don’t ever use 5 or 7.”

  11. Pingback: the switch, extended » scribbling damselfly » deborahkalin.com

  12. Pingback: How to enable hibernate mode on a Mac | Geek Guides

  13. Pingback: kaputtendorf » UpdateCheck

  14. Sometimes when resuming from Hibernation, the mouse cursor is still set to the wait wheel (black / white)?

  15. Thanks very much for this app; it works very well. However, I was wondering: I’d like to use this as a way to more quickly switch between Windows and Mac OS X. When I turned the machine back on, I held down the Option key but was not presented with a choice of OSes to load — it just went straight back into OS X.

    Do you know of any way to work around this so that I can chose to run Windows instead? I’m aware of Virtual Machines and the like but I am using Windows for gaming primarily and the games run far better natively.

    Thanks again for this great utility.

  16. Thank you very much for this script, I believe it will be very useful to me.

    Indeed, I have the same question as matalk: can’t I boot to an other OS while OSX is suspended-to-disk?

    I use rEFIt to load my Linux, but it is never loaded: the RAM is restored directly.

    That would be so nice to be able to switch from one OS to an other without the booting process…

  17. Pingback: How to hibernate Mac OS X | Code Mox

  18. Pingback: Como hibernar o Mac | iSengardian

  19. Pingback: Otra opciΓ³n para poner tu Mac a hibernar | Soy de Mac

  20. Hi Sveenie, thanks for this good script.

    I’d like to advice about the hibernatemode used, you use the mode 1, that is aceptable, but if we read at pmset manual ($ man pmset) we can read at the hibernatemode section (please everyone read it):

    ” We do not recommend modifying hibernation settings. Any changes you make
    are not supported. If you choose to do so anyway, we recommend using one
    of these three settings. For your sake and mine, please don’t use any-
    thing other 0, 3, or 25.”

    Basically the mode 25 is the same than 1 (hibernation ON, power OFF) but reducing the ammount of RAM written to disk to minimal. I tested this and the time for hibernation and restore is much better than using mode 1, besides the CPU is less used (CPU fan is lesser noisy for lesser time).

    So I modified the script to use mode 25 for my own, but I thought you’d like to know for modifing the script for everyone.

  21. Hi Sveenie, I use to have your software working fine in my older Mac OS but when I updated to Mac OS X 10.7.4 it stopped working and I get error message: “exit return_code = 0xe00002c1” do you know how do I fix it? Any help would be fine. Thank you.

  22. The reason for the 0xe00002c1 error is that the command line tool (pmset) needed to enable hibernation requires administrative privileges on Lion and later.

    So this tool won’t work on Lion+ as it stands. I think there are alternatives out there. Or you could do it from the command line.

  23. following previous comments regarding error 0xe00002c1 and hibernatemode 25, I slightly modified the script (Right click Hibernate in finder > Show package content, open Contents/Resources/Scripts/main.scpt)
    I use:
    do shell script “/usr/bin/pmset force -a hibernatemode 25” with administrator privileges
    and for the set old value:
    do shell script (“/usr/bin/pmset force -a hibernatemode ” & lastMode) with administrator privileges
    I only get the password prompt after the “hibernate?” dialogue and it works fine on Mountain Lion πŸ˜›

  24. Fix to Hibernate.App for 10.8 (and, I assume, 10.7)

    After upgrading to 10.8 from 10.6 I started getting the “exit return_code = 0xe00002c1”.

    After a lot of screwing around, I finally got it to work on 10.8.5. I think this should work on any version of MacOS that gives that error (10.7.x? 10.8.x).

    Note: Everything I know about AppleScript and the AppleScript Editor I learned in the past hour or so while developing this fix. There very well may be much better ways to accomplish this.

    I had to make two changes:

    (1) Adjust the hibernatemode of the pmset program. Apple strongly recommends that the only values that you use are 1, 3, and 25. My Mac had this set to 3. It seems that my fix will work only if this is set to either 1 or 25, BUT NOT 3.

    Launch the Terminal app (typically in the Utilities subfolder of Applications in Finder). Then use pmset to adjust the hibernatemode to 25 (as I said, 1 will work also). You will need administrator permission, which is accomplished with the sudo prefix, you will be prompted for your password. (If you do not have the necessary sudo privilege you will need to use the su command, which will require the “superuser” password.)

    (1a) Check the current value of hibernatemode:

    pmset -g

    Look through the output for the hibernatemode value:

    Currently in use:
    hibernatemode 3

    (1b) Next, if this is 3 (or any other value other than 1 or 25) change it to 1 or 25. This sets it to 25:

    sudo pmset -a hibernatemode 25

    The “-a” tells the system to use this in all modes (battery or AC power).

    (1c) Finally, exit from the Terminal:

    exit

    (2) Fix the AppleScript of the Hibernate.app. To do so, try to hibernate by clicking on the Hibernate launcher icon, and when you get the “exit return_code = 0xe00002c1” message, click on the “EDIT” button. This will open the AppleScript Editor. The last 6 lines of text are:

    ————————————————————————————-
    do shell script “/usr/bin/pmset force -a hibernatemode 1”
    ignoring application responses
    tell application “System Events” to sleep
    delay 5
    do shell script (“/usr/bin/pmset force -a hibernatemode ” & lastMode)
    end ignoring
    ————————————————————————————-

    Delete these 6 lines and replace them with this one line:

    ————————————————————————————-
    do shell script “/usr/bin/pmset sleepnow”
    ————————————————————————————-

    To save your changes, click the “Run” button (arrow in green circle). You can cancel when it ask “Do you want to hibernate? (suspend-to-disk)” or you can click OK to see that it does work. (This, running it once, was the only way I could find to save the changes).

    You should be all set. Clicking on the original launcher icon should now save-to-disk and shut off completely.

    ————————————————————————————-
    NOTE: If the author of this program is interested, these changes could be incorporated into a new version of the program. The script could check the current value of hibernatemode and set it to 1 or 25 (instead of requiring the user to use Terminal and sudo). The AppleScript for this would look like:

    do shell script “/usr/bin/pmset -a hibernatemode 1” with administrator privileges

    Ideally, this should only be done once the first time the script runs, and then suppressed on subsequent invocations when the value is found to be 1, because it will pop up a prompt for the user’s password.

    However, this is beyond my one hour self-taught knowledge of AppleScript.

  25. I had the error code 0xe00002c1 (I’m on Mavericks) but Howie’s changes fixed it perfectly for me, thanks Howie.

  26. Pingback: Die Linkpeitsche XVII

  27. Howie did a good job but he had some mistakes.

    β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”-
    do shell script β€œ/usr/bin/pmset force -a hibernatemode 1β€³
    ignoring application responses
    tell application β€œSystem Events” to sleep
    delay 5
    do shell script (β€œ/usr/bin/pmset force -a hibernatemode ” & lastMode)
    end ignoring
    β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”-

    is not equal to next code.

    β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”-
    do shell script β€œ/usr/bin/pmset sleepnow”
    β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”-

    β€œpmset sleepnow” command just perform a immediate sleep.

    But original code saves current hibernatemode and then after waking from hibernate, it restores original hibernatemode.

    But β€œdelay 5” is too short so hibernatemode changes to the original value back before hibernating and it doesn’t hibernate.

    So modified source is below.
    β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”
    do shell script “/usr/bin/pmset force -a hibernatemode 25” user name β€œ{USER NAME}” password β€œ{PASSWORD}” with administrator privileges

    ignoring application responses
    tell application “System Events” to sleep
    delay 30
    do shell script (“/usr/bin/pmset force -a hibernatemode ” & lastMode) user name β€œ{USER NAME}” password β€œ{PASSWORD}” with administrator privileges
    end ignoring
    β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”

  28. My mac is 10.9.4 OS X.

    If you type “pmset -g” in Terminal App, you will find useful option for hibernate.

    β€œstandby” causes kernel power management to automatically hibernate a machine after it has slept for a specified time period. This saves power while asleep.

    β€œstandbydelay” specifies the delay, in seconds, before writing the hibernation image to disk and powering off memory for Standby.

    In Terminal App, you can type the next command.

    ——————————————————————
    sudo pmset -a hibernatemode 3 standby 1 standbydelay 600
    ——————————————————————

    It turns on β€œstandby” and after 600 secondes since sleep, goes into hibernate.

Leave a Reply

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

 

This site uses Akismet to reduce spam. Learn how your comment data is processed.