3

我的一个applescript遇到了问题。我正在尝试创建一个applescript,在mac唤醒或屏幕保护程序在mac安全面板中停止后选中/取消选中调用密码的复选框。我将它与proximity.app一起使用,我的想法是当我回到家并且我的手机在范围内时,proximity.app会删除密码,但是当我超出范围时,它会放回密码。好吧...由于 Mountain Lion 中的新安全策略,我不得不使用 UI 脚本来执行此操作。

所以有超出范围的代码:

tell application "System Preferences"
set current pane to pane id "com.apple.preference.security"
tell application "System Events"
    tell process "System Preferences"
        tell first window
            tell first tab group
                click radio button 1
                if not 1 then click checkbox 1
                click menu item 6 of menu of pop up button 1
            end tell
        end tell
    end tell
end tell
quit

结束告诉

并且在范围内时:

tell application "System Preferences"
set current pane to pane id "com.apple.preference.security"
tell application "System Events"
    tell process "System Preferences"
        tell first window
            tell first tab group
                click radio button 1
                click checkbox 1
            end tell
        end tell
    end tell
end tell
quit

结束告诉

我想要改进的是一种在选中或取消选中之前先验证该框是否选中或取消选中的方法。

谢谢你的帮助。

4

1 回答 1

6

只需检查checkbox.

0 = 取消选中,1 = 选中

tell application "System Preferences" to ¬
    reveal anchor "Advanced" of pane id "com.apple.preference.security"
tell application "System Events"
    tell first tab group of first window of process "System Preferences"
        tell checkbox 1 to if value is 0 then click -- checkbox was not checked.
    end tell
end tell
quit application "System Preferences"
于 2012-10-23T02:36:41.353 回答