It’s been a while since I last posted (more than a year or so?)… but I’m back at it (actually this would be called SOG, or Studie Ontwijkend Gedrag in the Netherlands…
Anyway… I’d like to have a way to unlock my mac using my IR remote, but requiring a password if it’s being unlocked in any other way…
beep
do shell script "pmset displaysleepnow"
delay 5
beep
tell application "System Events"
set require password to wake of security preferences to false
end tell
do shell script "defaults write com.apple.screensaver askForPassword -bool false"
do shell script "caffeinate -u -t 1"
do shell script "defaults write com.apple.screensaver askForPassword -bool true"
tell application "System Events"
set require password to wake of security preferences to true
end tell
To ‘fix’ the issue I added this code to the bottom (for testing purposes);
delay 20
do shell script "pmset displaysleepnow"
do shell script "caffeinate -u -t 1"
The other ‘fix’ is having System Events enter the password manually, but that isn’t as ‘sexy’ as I would like to have it.
Anyway, the problem is that when unlocking the screen with the requirement of a password disabled, the lock window still is active and ‘traps’ any and all focus onto itself. Therefor disable all text and most of the UI input’s.
Does anyone know a way to kill the lockwindow/refocus onto other applications?
P.s. I did try “Tell application ‘Finder’ to activate”, though that doesn’t work.
I thought the lock window might’ve actually been present but hidden (as the focus is trapped by it), and tried to ether the password anyway (using below code). Though that doesn’t seem to work… I thought up another way to the same result but it [strikethrough]might[/strikethrough] will take a lot longer before the display “wakes up”.
-- To grab the user's password without hardcoding it into the script (credits to Inspira.io)
on getPassword(keychainItemName)
set my_password to do shell script ("security 2>&1 >/dev/null find-generic-password -gl " & quoted form of keychainItemName & " | cut -c 11-99 | sed 's/\"//g'")
end getPassword
set my_password to getPassword("PassKeychainName")
tell application "System Events"
log my_password
keystroke my_password --password
delay 1
key code 52 -- enter
end tell
The second idea I came up with was to, after the script gets called lower the display’s screen brightness to 0 before actually waking it up. Then enter the users password, and then restoring the previous screen brightness.