iPains

Seasoned Windows power user acquires MacBook Pro. Switches cold turkey. Was it worth the iPain?

Sunday, April 30, 2006

Toggle Screen Saver AppleScript

Most Windows power users are familiar with "locking" their computers when left unattended. This is achieved by waiting for the screen saver to start (which can be set to require a password upon return) or by typing windows-L. This is especially important if you work with those possessing a mischievous sense of humor*.

So naturally I wondered how to do the equivalent of windows-L in OS X, and to my surprise no such equivalent exists. The closest thing one can do is set a "hot corner" to trigger the screen saver, which means if you move your mouse to a specific corner of your display the screen saver will start. Since I think this is lame as it is prone to misfire, I hunted down a cool AppleScript that does what I desire (toggles the screen saver with a shortcut key), as follows:

try
tell application "System Events"
set the process_flag to (exists process "ScreenSaverEngine")
end tell
if the process_flag is true then
ignoring application responses
tell application "System Events" to quit
end ignoring
else
set the target_app to ((path to "dlib" from system domain as string) &
"Frameworks:ScreenSaver.framework:Versions:A:Resources:ScreenSaverEngine.app") as alias
tell application (target_app as string) to launch
end if
on error
beep
end try
I placed this script under ~/Library/Scripts, named it "Toggle Screen Saver.scpt," and using Quicksilver I was able to run this script with a trigger of option-L. Obviously one should check "Require password to wake this computer from sleep or screen saver" under the System Preferences -> Security settings.


* The CEO of my company has caught my computer unlocked twice, and one time changed my language settings to Russian. That took a while to fix. The other time he made a smiley face with my desktop icons. Bastard.

5 Comments:

At 2:02 AM, Anonymous Anonymous said...

Smiley face with icons...awesome.

 
At 2:24 AM, Anonymous Anonymous said...

Hey chrs, this is mark's brother, Roman. He sent me the link, as I also just switched to OSX from about 5 years of using Linux as my Laptop desktop. So I am getting going through similar iPains as well.

As far as locking the screen goes - I am used to doing it with an icon on my tray - in gnome. So the link below tells you how to get that icon to appear:
http://www.macworld.com/weblogs/macosxhints/2006/01/lockscreen/index.php

I know use the last 1/3 of the tip, where it tells you how to use preferences to get the icon up. But if you anble fast-user switching you can logout - similar to OS X.

 
At 2:56 AM, Anonymous Anonymous said...

sorry, i got bumrushed by a few visitors and finished that comment in too much of a hurry to make sense....

So my locking tips are as follows:

-to get a padlock on the tray so you can lock from the menu there go to:
Applications/Utilities folder ->
Start Keychain Access
Keychain Access: Preferences
General tab : select Show Status in Menu Bar

Now you can lock it with 2 clicks in the icon try, just like it usually works in Gnome/Kde. Which I guess is not that exciting to you :)

 
At 4:10 PM, Anonymous Anonymous said...

Just a quick note - blogger's formatting ate part of the script, in the line that begins "set the target script". The parens are unbalanced, and some odd high-ascii has crept in, I'm guessing to try and show that it should all be on one line.

 
At 4:46 PM, Blogger Chris said...

Thanks. Fixed.

 

Post a Comment

<< Home