Sleep & Lockscreen
Posted on October 29, 2009
Filed Under Automation | Comments Off
DrDrang has up a nice little addition to the Lockscreen hint I’d linked to last week. Basically in addition to locking the screen by bringing up the Login Screen he puts the display to sleep. He does this with a Google app he then calls with an Applescript. However there is an easier way.Now as you recall to lock the screen you just call
/System/Library/CoreServices/Menu\ Extras/User.menu/Contents/Resources/CGSession -suspend
If you want to also suspend the display (which I like to do so my wife won’t complain about the light) just add the following line to your shell script.
osascript -e "tell Application \"System Events\" to sleep"
Presto-Chango your screen is black until you move the mouse or click a key.
Now be aware the whole computer is asleep. If you’re running code in the background you don’t want to do this. The solution for that is to just sleep the display is to use pmset. That’s how I do it. So my whole script looks like this:
/System/Library/CoreServices/Menu\ Extras/User.menu/Contents/Resources/CGSession -suspend pmset force -a displaysleep 1 sleep 100 pmset force -a displaysleep 100
Of course you might not want to do this exactly like this. Look at the pmset options. The above sets this sleep pattern for any power source whereas you might want battery sleep time and powered sleep time handled differently. I rarely set sleep time except in this case so I don’t mind just setting it to 100 minutes.
I probably should have mentioned this in that post since I had already added that to my shell script. But typically for sideblog entries I just post the link and then at most offer a sentence or two of commentary.
I should note that this shell script run as a Service from Automator is probably my most run service.
Related posts:
.jpg)