Thread: Lock computer?
View Single Post
  #24  
Old March 11th, 2009, 10:57 AM
simbalala simbalala is offline
Registered User
 
Join Date: Jul 2005
Posts: 897
Thanks: 0
Thanked 5 Times in 5 Posts
simbalala is on a distinguished road
Keyboard shortcut to lock screen

This AppleScript will lock the screen providing you have the “Lock” icon displayed in your menu bar. You enable that through Key Chain Access preferences. I use this with a QuicKeys keyboard shortcut to lock the screen.

Code:
tell application "System Events" to tell the front menu bar of process "SystemUIServer"
	set foundMenu to false
	set menu_extras to value of attribute "AXDescription" of menu bar items
	repeat with x from 1 to the length of menu_extras
		if item x of menu_extras is equal to missing value then
			tell menu bar item x
				click
				tell first menu item of front menu
					if name is equal to "Lock Screen" then
						set foundMenu to true
						exit repeat
					end if
				end tell
			end tell
		end if
	end repeat
	if foundMenu is equal to false then
		keystroke return
	end if
end tell
Reply With Quote