All,
I’d like to require the user to enter the administrator password such that if they don’t or if they enter incorrectly, then the password to wake is enabled and the screen is locked. I’m currently using this code:
if not CheckPassword() then LockScreen()
on CheckPassword()
try
do shell script "echo" with administrator privileges
return true
on error
tell application "System Events" to set require password to wake of security preferences to true
return false
end try
end CheckPassword
on LockScreen()
tell application "System Events" to tell process "SystemUIServer" to click (first menu item of menu 1 of ((click (first menu bar item whose description is "Keychain menu extra")) of menu bar 1) whose title is "Lock Screen")
end LockScreen
This works alright, but I’d like to make it so that if the user doesn’t enter the password within say 15 seconds, then the password request times out and CheckPassword() returns false. I’ve tried using a timeout:
on CheckPassword()
try
with timeout of 15 seconds
tell application "System Events"
do shell script "echo" with administrator privileges
end tell
end timeout
return true
on error
tell application "System Events" to set require password to wake of security preferences to true
return false
end try
end CheckPassword
but the timeout does not occur. I guess that the password prompt doesn’t count towards the timeout for System Events to perform the “do shell script” command.
How can I achieve the same method of having the user enter an administrator password with a timeout?
Thanks.