I have been using this hint until it broke in Lion. (See the last comment in that hint.)
After not being able to find a complete solution, I came up with this:
*Please note that this is not a secure solution. Your account password is stored in plain text, just as in the original hint.*
There is a way to collect the password from the keychain (see the above link and read through the comments), but I don't quite understand that just yet.
Also, this comes with the usual use at your own risk and I am not responsible if your computer explodes warnings.
on run {input, parameters}
set theUser to "USERNAME"
set theUser to do shell script "/usr/bin/id -u " & theUser
do shell script "/System/Library/CoreServices/Menu\\ Extras/User.menu/Contents/Resources/CGSession -switchToUserID " & theUser
tell application "System Events"
set token to "1"
repeat while token = "1"
if exists process "SecurityAgent" then
delay 1
keystroke "PASSWORD"
keystroke return
set token to "0"
end if
end repeat
end tell
return input
end run
Mac OS X Hints
http://hints.macworld.com/article.php?story=20110813074611411