Toggle OSX screen saver password lock
In OSX it is you can set it so the screen saver asks for a password to unlock. The normal way to set this is to go to System Preferences > Security Pane > General Tab and check the tick box. Here is a quick Applescript to toggle the screen saver password setting. I wrote this in response to this request on Apple Dicsussions. There are also another couple of responses there that use Systems Events GUI scripting to open System Preferences. This script used the UNIX command 'defaults' to set the preferences .plist for the screen saver directly without opening any windows.
-- John Maisey -- 4 Feb 2011 -- www. nhoj.co.uk
set myFlag to (do shell script "defaults read com.apple.screensaver askForPassword")
set myFlag to 0
do shell script "defaults write com.apple.screensaver askForPassword -int " & ((myFlag + 1) mod 2)
Now and again I respond to posts at Apple Discussions. Due to the nature of forums the information is quickly buried there. This post is just to document the Applescript in case anyone else finds it useful.