Tick a checkbox only if it's not selected

后端 未结 2 1010
灰色年华
灰色年华 2021-01-13 23:55

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

tell application \"System Events\"
  tell process \"Example Process\"
    click checkbox         


        
2条回答
  •  星月不相逢
    2021-01-14 00:19

    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
    

提交回复
热议问题