2015-04-04 69 views
3

我想以編程方式解鎖mac。目前我正在使用蘋果腳本來提出這個建議。它工作得很好,但問題是這是一個耗時的過程。大約需要4-5秒才能執行腳本。這是我使用NSAppleScript執行的腳本。請建議我如何讓它快速工作。或任何其他最快的可能方式。由於以編程方式解鎖MAC

tell me to activate\n 
tell application \"System Events\" to keystroke \"PASSWORD\"\n 
tell application \"System Events\" to keystroke return\n 
tell application \"System Events\" to keystroke return" 
+0

「我希望以編程方式解鎖Mac電腦。」 - 爲什麼? – foo 2015-04-04 13:34:32

+0

如果您將純文本密碼放入代碼中,那麼鎖定它確實沒有意義。 – 2015-04-04 14:37:54

+0

它的腳本很慢嗎?沒有登錄?如果可能的話,你也許可以加快速度,不會恢復狀態。 – stevesliva 2015-04-04 19:08:44

回答

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

tell application "System Events" 
    stop current screen saver 
end tell 

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

當我鎖定我的Mac並嘗試用給定的腳本解鎖時,它不會執行任何操作,而且我的Mac也會詢問用戶名和密碼。在系統prefereces>安全和隱私我有禁用自動登錄未選中。 – Ashutosh 2015-08-27 18:56:07

+0

我認爲root權限需要執行thiis腳本嗎? – plettix 2016-02-22 10:35:51