--This application will require the password to wake from
--sleep and then start the screen saver. Once the screen
--saver is finished running, the password is no longer required
global screenSaverOn
on run
-- Sets computer to require a password
tell application "System Events"
tell security preferences
set require password to wake to true
end tell
end tell
-- Launches the screen saver
tell application id "com.apple.ScreenSaver.Engine" to launch
set screenSaverOn to true
end run
-- Polls the system to see if the screen saver is running
on idle
tell application "System Events"
-- Polls the system to see if the screen saver is running
set screenSaverOn to (name of processes) contains "ScreenSaverEngine"
end tell
if not screenSaverOn then
-- Once screensaver is turned off, prompts user to return to not require password. Without this, someone could simply wake the screensaver, cancel the password prompt, and then wake the screensaver again to access the session.
display dialog "Return to no password required to wake?" buttons {"No", "Yes"} default button 2 giving up after 30 --Change this number to adjust time before prompt disappears
if the button returned of the result is "Yes" then
tell application "System Events"
tell security preferences
set require password to wake to false
end tell
end tell
tell me to quit
end if
end if
-- delays 5 seconds before next check to reduce CPU load
return 5
end idle
-- Allows script to be quit cleanly as when scheduled shutdown or logout occurs.
on quit
continue quit
end quit