2013-12-10 32 views
7

我正在使用AppleScript從外部設備(觸發器)鎖定Mac並從同一設備解鎖它。使用AppleScript解鎖OS-X(小牛)後,鍵盤無法響應

鎖定效果很好,但解鎖我的Mac鍵盤和打擊墊變得無法響應。奇怪的是,當我鎖定後移動慕斯,並獲得密碼登錄,如果我輸入密碼解鎖使鍵盤響應,然後才能。

這是我不知道的某種安全設置嗎?我怎麼解決它?

這裏是我使用的腳本:

鎖:

tell application "System Events" 
tell security preferences 
set require password to wake to true 
end tell 
end tell 

activate application "ScreenSaverEngine" 

解鎖:

tell application "System Events" 
tell security preferences 
set require password to wake to false 
end tell 
end tell 

tell application "ScreenSaverEngine" to quit 

請幫我絕望。此外,如果你有另一種方法,你知道用代碼鎖定/解鎖我的Mac,我很樂意嘗試一下!

謝謝!

更新:要清除密碼設置代碼(需要密碼)時,不會出現問題。 意義刪除那些3線:

tell security preferences 
    set require password to wake to true 
end tell 

沒有這個問題,這就是爲什麼我認爲這可能是一些安全的事情我不知道的。

更新(2013年12月26日):我沒有找到任何解決方案,賞金完成,我做的是將使用ActionScript我的密碼(也許這能幫助有同樣的問題,其他人)等什麼。如果你確實有另一個我很想知道的解決方案。

回答

3

請嘗試下面的鎖定屏幕,我使用相同的鎖定或解鎖時沒有問題。希望這可以幫助。

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 
+0

它的工作原理,但我的問題是與要求密碼設置爲true。所以當我用你的代碼做這件事時,我會得到相同的結果。當添加 含義: 告訴安全喜好的\ n 組需要密碼才能喚醒真\ n 端告訴\ n 下的第二行,我得到同樣的問題。如果我從我的代碼中刪除這3行,它也與您的代碼一樣。 對不起,我不清楚這一點。 你有任何線索如何解決? – Idan

3

今天晚些時候我可以在小牛機上做更多的測試。與此同時,我有一點理論 - 你有沒有測試過其他屏幕保護程序「活躍」?我之所以這麼說是因爲我確實有一些屏幕保護程序是一個小bug,而且我知道至少有一個屏幕保護程序需要更新Mavericks。你在使用哪一個?

[更新:]我確實得到了小牛,並沒有看到你描述的問題,或者至少是這種嚴重性的問題。不過,我確實有點奇怪,可能與時間有關。如果你像這樣構建你的腳本呢?對我來說,它涵蓋了像「連接無效」這樣的錯誤(我承認這有點'危險';它可能是一個上限,試圖通過在其中放置一個計數器來激活它的次數的上限):

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