I’m trying to make a ‘deepsleep’ script that puts my computer to hibernate, but puts the sleep settings back to sleep only after hibernating (so I can just close my laptop for sleep only, without having to change the configuration).
I constructed a script to achieve this, and for just a moment I considered myself a genius:
do shell script "sudo pmset -a hibernatemode 1" tell application "System Events" to sleep do shell script "sudo pmset -a hibernatemode 0"
I have to add that I fiddled with my configuration so that I don’t have to give my root password for executing these commands.
My moment of genius was only short. This works when running it from the scripteditor, but does not work as soon as I save the script and try to run it from Spotlight or the script menu (and that was my ultimate goal). Not working means that my script is executed, but it goes into sleep only, not hibernation as expected. It seems like the last line of the script is executed before the system goes to sleep. It also takes a very long time between the screen going blank and the actual sleeping (also for sleep only), which is not the case in the script editor.
- Why is there a difference between running a script from the script editor and SpotLight, and what are these differences?
- Any suggestions on how to make it work?
If you need more on configuration to answer this question, I will be happy to provide it.
Model: MacBook Pro
Browser: Safari 525.20.1
Operating System: Mac OS X (10.5)