Applescript : Lock & UnLock MacOS based on device stats
delay 5

Can use this but not really secure :

tell application "System Events"
    if ((get name of every process) contains "ScreenSaverEngine") then
        set pw to "Password Here"
        tell application "ScreenSaverEngine" to quit
        delay 0.5
        keystroke pw
        keystroke return
        -- set require password to wake of security preferences to false
    end if
end tell