BlueSense AppleScripts

How to enable the screensaver password on Mac OS X in AppleScript

Launch the screensaver and enable the password to protect your Mac.

script EnableScreenSaverPassword
		-- method 1
		tell application "System Events"
			tell security preferences
				set properties to {require password to wake:true}
			end tell
			tell application id "" to launch
		end tell
		-- method 2 (change user defaults but do not prompt for the password)
		do shell script ("/usr/bin/defaults write askForPassword -int 1")
		do shell script ("/usr/bin/defaults write askForPasswordDelay -int 5")
		-- Launch the  ScreenSaver
		tell application id "" to launch
	on error errString number errorNumber
		log (errString)
	end try
end script