【问题标题】:Verify a checkbox before clicking with Applescript在使用 Applescript 单击之前验证复选框
【发布时间】:2012-10-12 20:59:38
【问题描述】:

我的一个 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

说完

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

感谢您的帮助。

【问题讨论】:

    标签: macos checkbox applescript osx-mountain-lion


    【解决方案1】:

    只需检查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"
    

    【讨论】:

    • 是的,谢谢!刚刚采用这种方式:code 告诉应用程序“系统偏好设置”将当前窗格设置为窗格 ID“com.apple.preference.security”告诉应用程序“系统事件”告诉进程“系统偏好设置”告诉第一个窗口告诉第一个选项卡组单击单选按钮 1 告诉复选框 1,如果值为 0,则单击 - 未选中复选框。单击弹出按钮 1 菜单的菜单项 6 end tell end tell end tell end tell quit end tell code
    猜你喜欢
    • 2023-01-20
    • 1970-01-01
    • 1970-01-01
    • 2022-09-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-05-18
    相关资源
    最近更新 更多