仅在未选中复选框时对其打勾 [英] Tick a checkbox only if it's not selected

查看:115
本文介绍了仅在未选中复选框时对其打勾的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Applescript中使用UI脚本时,您可能需要勾选一个复选框:

When UI Scripting in Applescript, you might want to tick a checkbox:

tell application "System Events"
  tell process "Example Process"
    click checkbox "Example Checkbox" of sheet 1 of window 1
  end tell
end tell

这有问题.如果示例复选框已被选中,则实际上您已取消选中该复选框.您如何才能仅在尚未选中的情况下才选中该复选框"?

This has a problem. If the example checkbox is already ticked, you actually un-tick the box. How can you "tick the checkbox only if it's not already ticked"?

推荐答案

各种UI项都有可以测试的属性.对于复选框,属性将是1还是0,具体取决于是否选中它,因此您可以直接使用该值,也可以将其强制转换为布尔值,例如:

The various UI items have properties you can test. For checkboxes, the value property will be 1 or 0 depending on whether it is checked or not, so you can use the value directly or coerce to a boolean, for example:

tell application "System Events" to tell process "Example Process"
    set theCheckbox to checkbox "Example Checkbox" of sheet 1 of window 1
    tell theCheckbox
        if not (its value as boolean) then click theCheckbox
    end tell
end tell

这篇关于仅在未选中复选框时对其打勾的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆