1 Reply Latest reply: Jan 11, 2013 11:13 PM by Hiroto
MacOSXNoob Level 1 Level 1 (5 points)

I have found scripts that put a computer into hibernation, or deep sleep, but I am looking for one that does not require a password. Also, I do not want to save my password into the script, because I would like to give it to a friend.

 

Another thing:

I have seen pmset -a hibernatemode _

what does each number in the _ space mean?

Also, I would like a script for safe and quick sleep and restart if possible.

 

Thank You


MacBook Pro, OS X Mountain Lion (10.8.2)
  • Hiroto Level 5 Level 5 (6,040 points)

    Hello

     

    Try something this:

     

    --applescript 
    set sh to "# hibernate
    hmode=$(pmset -g | awk '/hibernatemode/ {print $2}')    # current hibernatemode
    # hmode=3    # default hibernatemode for notebook machine
    # hmode=0    # default hibernatemode for desktop machine
    pmset force hibernatemode 1
    pmset sleepnow
    pmset force hibernatemode $hmode &>/dev/null &
    "
    do shell script sh
    --end of applescript
    

     

    For some reason, '&>/dev/null &' is required for the last command when used with 'do shell script'.

     

    In shell, you can simply do this.

     

    #!/bin/bash
    #
    # hibernate
    #
    hmode=$(pmset -g | awk '/hibernatemode/ {print $2}')    # current hibernatemode
    # hmode=3    # default hibernatemode for notebook machine
    # hmode=0    # default hibernatemode for desktop machine
    pmset force hibernatemode 1    # hibernate regardless of battery status
    pmset sleepnow
    pmset force hibernatemode $hmode    # restore the original value
    

     

    Tested with 10.5.8.

     

    Regards,

    H

     

    P.S. See pmset(1) manpage for hibernatemodes.

    https://developer.apple.com/library/mac/documentation/Darwin/Reference/ManPages/ man1/pmset.1.html