Home » Questions » Computers [ Ask a new question ]

Applescript to lock the screen

Applescript to lock the screen

I need a little Applescript to lock the screen, the same behaviour I get when I click the Keychain icon in the menu bar and choose "Lock screen".

Asked by: Guest | Views: 212
Total answers/comments: 2
Guest [Entry]

"Do you realize in the Security Preference Pane you can require a password to wake from the screen saver, but it defaults to not requiring authentication?

Then you can activate the screen saver with your method, or this AppleScript:

do shell script ""open /System/Library/Frameworks/ScreenSaver.framework/Versions/A/Resources/ScreenSaverEngine.app""

You could also add the Keychain lock and use this AppleScript that I found here.

activate application ""SystemUIServer""
tell application ""System Events""
tell process ""SystemUIServer""
repeat with i from 1 to number of menu bar items of menu bar 1
tell menu bar item i of menu bar 1
click
try
if name of menu item 1 of front menu is ""Lock Screen"" then
click menu item ""Lock Screen"" of front menu
exit repeat
end if
end try
end tell
end repeat
end tell
end tell

This script requires Universal Access --> Enable access for assistive devices be checked."
Guest [Entry]

"Here is a solution from Mac OS X Hints, but it seems to requires installing JackSMS first, whatever that is. Then you can do

tell application ""JackSMS"" to set lock screen to true
tell application ""JackSMS"" to set lock screen to false"