简体   繁体   English

使用AppleScript解锁OS-X(Mavericks)后,键盘无响应

[英]Keyboard isn't responsive after unlock OS-X (Mavericks) using AppleScript

I'm using AppleScript to lock the Mac from an external device (trigger) and unlock it from this same device. 我正在使用AppleScript从外部设备(触发器)锁定Mac并从同一设备解锁。

Locking works great but when unlock my Mac keyboard and pads becomes unresponsive. 锁定效果很好,但解锁时我的Mac键盘和打击垫变得无法响应。 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! 此外,如果您有其他方法,您知道使用代码锁定/解锁我的Mac,我很乐意尝试一下!

Thanks! 谢谢!

UPDATE: To be clear when removing the password setting code (require password) the issue doesn't appear. 更新:要清除密码设置代码(需要密码)时,问题不会出现。 Meaning removing those 3 lines: 意思是删除这3行:

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). 更新(2013年12月26日):我没有找到任何解决方案和赏金完成所以我正在做的是使用ActionScript插入我的密码(也许这可以帮助其他人有同样的问题)。 If you do have another solution I would love to know. 如果您有其他解决方案,我很乐意知道。

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

Later today I'll be able to do more testing on a Mavericks machine. 今天晚些时候,我将能够在Mavericks机器上进行更多测试。 In the meantime, I have a little theory -- have you tested this with other screen savers "active"? 与此同时,我有一个小理论 - 你有没有测试过其他屏幕保护程序“活跃”? I say this because I do have a couple of screen savers that are a little buggy, and I know that at least one of them needs an update for Mavericks. 我之所以这么说,是因为我确实有几个屏幕保护程序有点儿,我知道其中至少有一个需要小牛队的更新。 Which one are you using? 你在用哪一个?

[UPDATE:] I did get on Mavericks and did not see the problems you described, or at least problems of that severity. [更新:]我确实得到了小牛队,并没有看到你描述的问题,或者至少是那种严重性的问题。 I did get a little weirdness, though, possibly having to do with timing. 不过,我确实有点古怪,可能与时间有关。 What if you structure your script like this? 如果您像这样构建脚本怎么办? For me, it covers for errors like "connection invalid" (I admit this is a little 'dangerous'; it might be good to put an upper limit of how many times it 'try's the activate by putting a counter in there): 对我而言,它涵盖了诸如“连接无效”之类的错误(我承认这有点“危险”;通过在其中放置一个计数器来设置激活尝试次数的上限可能是好的):

tell application "System Events"
    tell security preferences
        set require password to wake to false
    end tell
end tell
set connectionValid to false
repeat until connectionValid
    try
        activate application "ScreenSaverEngine"
        set connectionValid to true
    on error e
    end try
end repeat

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM