Tick a checkbox only if it's not selected

后端 未结 2 1031
灰色年华
灰色年华 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 Answer from Red_menace isn't fully clear, you could think making such thing like this:

    set theCheckbox to checkbox "Random order" of tab group 1 of window "Desktop & Screen Saver"
                tell theCheckbox
                    if false then click theCheckbox -- if false does not reference the 'theCheckbox', it is simply doing nothing
                end tell
    

    Then it will never compute the if clause.

    Therefore I changed to middle part to

    set theCheckbox to checkbox "Change picture:" of tab group 1 of window "Desktop & Screen Saver"
            tell theCheckbox
                set checkboxStatus to value of theCheckbox as boolean
                if checkboxStatus is false then click theCheckbox                   
            end tell
    

    And then it worked.

提交回复
热议问题