2012-03-13 87 views
3

当AppleScript的UI脚本,你可能要勾选复选框:勾选仅如果它不选择一个复选框

tell application "System Events" 
    tell process "World Conqueror" 
    click checkbox "Sell wives as slaves" of sheet 1 of window 1 
    end tell 
end tell 

这有问题。如果售卖妻子的复选框已经勾选,您实际上不勾选该框,您将不得不永远与妻子同住。你如何“只在未勾选时勾选复选框”?

回答

10

各种UI项目都具有可测试的属性。对于复选框,在物业将取决于它是否被选中或不为1或0,这样你就可以直接使用值或强迫为布尔值,例如:

tell application "System Events" to tell process "World Conqueror" 
    set theCheckbox to checkbox "Sell wives as slaves" of sheet 1 of window 1 
    tell theCheckbox 
     if not (its value as boolean) then click theCheckbox 
    end tell 
end tell 
1

从Red_menace ISN答案并不完全清楚,你可以这样想:

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 

然后它永远不会计算if子句。

所以我改成中间环节

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 

然后它的工作。

相关问题