2012-03-13 70 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 

然後它的工作。

相關問題