Is there some command line or AppleScript that I can write/run to make the machine go to sleep automatically or even better, into hibernate mode?
I can run the program as root.
osascript -e 'tell application "Finder" to sleep'
To go into Hibernate mode, you'll need to set the correct setting on the power manager.
Possible Settings:
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.
So after all that, if you want to hibernate automatically and you don't have secure VM turned on then you could run the following shell commands (as a setuid root script):
pmset -a hibernatemode 1; osascript -e 'tell application "Finder" to sleep'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With