Created
July 26, 2012 00:30
-
-
Save shuujii/3179564 to your computer and use it in GitHub Desktop.
Deep sleep and restore default hibernatemode on Mac
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| PLIST=~/Library/LaunchAgents/my.resume.plist | |
| RESUME=$(cd $(dirname $0); pwd)/mac-resume | |
| machine_suspend() { | |
| cat <<EOF > $PLIST | |
| <?xml version="1.0" encoding="UTF-8"?> | |
| <!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" | |
| "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | |
| <plist version="1.0"> | |
| <dict> | |
| <key>Label</key> | |
| <string>$(basename $PLIST .plist)</string> | |
| <key>ProgramArguments</key> | |
| <array> | |
| <string>$RESUME</string> | |
| </array> | |
| <key>StartInterval</key> | |
| <integer>60</integer> | |
| </dict> | |
| </plist> | |
| EOF | |
| [ -e $RESUME ] || ln -s mac-suspend $RESUME | |
| sudo pmset -a hibernatemode 1 | |
| launchctl load $PLIST | |
| pmset sleepnow | |
| } | |
| machine_resume() { | |
| sudo pmset -a hibernatemode 3 | |
| launchctl unload $PLIST | |
| rm -f $PLIST | |
| } | |
| case $(basename $0) in | |
| mac-suspend) machine_suspend ;; | |
| mac-resume) machine_resume ;; | |
| esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment