Create key-based sleep and lock shortcuts

Nov 20, '02 08:16:26AM

Contributed by: conrad

After switching to MacOS a year ago, I found that I missed being able to lock my workstation with a key combo. Here's my solution. I rely on a fantastic piece of shareware from Unsanity called FruitMenu which, in addition to bringing back the Apple Menu, allows me to assign keyboard shortcuts to any application. It's $7 well spent. With FruitMenu and the keyboard, I can:

  1. Sleep
    FruitMenu has a menu item for sleeping by default. I added it to my menu and assigned a key combo to it. Note: I've found that key combos that use the [command] key do not always register. This may be a bug, but more likely, it's due to a foreground app taking priority for the key combo. Hence, I assign combos with [ctrl] and [option] together.

  2. Lock
    Locking is implemented through the Screen Saver as usual. I set my Screen Saver to "Never" launch in the preferences, but to require a password. Then I dragged /System -> Library -> Frameworks -> ScreenSaver.framework -> Resources -> ScreenSaverEngine to the FruitMenu. I renamed it to "Lock Workstation" and assigned a key combo.

  3. Both sleep and lock
    Open the AppleScript Script Editor and enter the following script:
      launch application "ScreenSaverEngine"
    delay 5
    tell application "Finder"
    sleep
    end tell
    Then Save As Run-Only, select "Application" under Format, and check "Never Show Startup Screen." I saved it as "Lock & Sleep Workstation". For vanity, I changed the icon to the Keychain icon as well. Finally, I dragged my newly created application to my menu and assigned it a key combo. Naturally, you can also put this application into your dock and launch it from there, or any other launcher application.
I hope this hint is helpful and is not a repeat of a previous hint.

[Editor's note: I think bits of this have been repeated in previous hints, but this is a nice summary of three different keyboard-based solutions for sleeping and/or locking your machine.]

Comments (8)


Mac OS X Hints
http://hints.macworld.com/article.php?story=20021120051626920