Toggling screensaver password with script

The same thing happens to me in 10.9. I also tried changing require password to wake of security preferences and putting displays to sleep instead of starting a screen saver:

tell application "System Events"
    set require password to wake of security preferences to true
    --start screen saver "Random"
    do shell script "pmset displaysleepnow"
    delay 5
    set require password to wake of security preferences to false
end tell

Neither of them helped though.

You might log out to the fast user switching screen instead of locking the screen though:

/System/Library/CoreServices/Menu\ Extras/User.menu/Contents/Resources/CGSession -suspend