I'm using AppleScript to lock the Mac from an external device (trigger) and unlock it from this same device.
Locking works great but when unlock my Mac keyboard and pads becomes unresponsive. Weird thing is when I move mousse after locking and get the password login if I enter the password the unlock makes keyboard responsive and only then.
Is it some kind of security settings I'm not aware of? How could I solve it?
Here is the script I'm using:
Lock:
tell application "System Events"
tell security preferences
set require password to wake to true
end tell
end tell
activate application "ScreenSaverEngine"
Unlock:
tell application "System Events"
tell security preferences
set require password to wake to false
end tell
end tell
tell application "ScreenSaverEngine" to quit
Please help I'm desperate. Also if you have another method you know to lock/unlock my Mac using code I would love to try it out!
Thanks!
UPDATE: To be clear when removing the password setting code (require password) the issue doesn't appear. Meaning removing those 3 lines:
tell security preferences
set require password to wake to true
end tell
Doesn't have this issue, this is why I think it could be some security thing I'm not aware of.
UPDATE (26 Dec 2013): I didn't find any solution and bounty finished so what I'm doing is inserting my password using ActionScript (maybe this could help others having same issue). If you do have another solution I would love to know.
AppleScript is a scripting language created by Apple Inc. that facilitates automated control over scriptable Mac applications. First introduced in System 7, it is currently included in all versions of macOS as part of a package of system automation tools.
To bypass the quit handler, choose Quit from the applet's menu while holding down the Shift key, or press the Command-Shift-Q key combo while the applet is the active or front application.
Having too many scripting additions slows AppleScript's load time, since it must process that many more files in the Scripting Additions folder. Also, more scripting additions means more event and class names must be parsed from 'aete' resources and added to the AppleScript symbol table.
You may have accidentally set an option that changes how your keyboard operates. Choose Apple menu > System Preferences, click Accessibility, click Keyboard, then click Hardware. Make sure Slow Keys is turned off. If Slow Keys is on, you must press and hold a key longer than usual before it’s recognized.
The much harder part was figuring out how to simulate typing the Enter (or Return) key from AppleScript. Without further ado, here's the answer: I found this answer by downloading a program named Full Key Codes. It's a simple program that shows the codes for the keys as you press them on your keyboard.
Choose Apple menu > System Preferences, click Accessibility, click Pointer Control, then click Alternate Control Methods. Make sure Mouse Keys is off. Choose Apple menu > System Preferences, click Keyboard, then click Input Sources. Select “Show Input menu in menu bar.”
Choose Apple menu > System Preferences, click Accessibility, click Keyboard, then click Hardware. Make sure Slow Keys is turned off. If Slow Keys is on, you must press and hold a key longer than usual before it’s recognized. Choose Apple menu > System Preferences, click Accessibility, click Pointer Control, then click Alternate Control Methods.
Try below for locking the screen, I am using the same and no issues while locking or unlocking. Hope this helps.
try
tell application "System Events"
set the process_flag to (exists process "ScreenSaverEngine")
end tell
if the process_flag is true then
ignoring application responses
tell application "System Events" to quit
end ignoring
else
set the target_app to ((path to "dlib" from system domain as string) & "Frameworks:ScreenSaver.framework:Versions:A:Resources:ScreenSaverEngine.app") as alias
tell application (target_app as string) to launch
end if
end try
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With