2017-07-17 22 views
0

作爲前言,我是非常新的AppleScript的工作AppleScript在投入工作流時失敗

我有一個非常簡單的,工作的AppleScript時在Automator的工作流程/應用程序的一部分運行總是失敗。我知道該腳本可以工作,因爲我可以在腳本編輯器中多次運行它,並且沒有錯誤。

下面是腳本:

activate application "Chess" 

tell application "System Events" to tell process "Chess" 
    click menu item "Preferences…" of menu "Chess" of menu bar item "Chess" of menu bar 1 

    tell window 1 
      repeat until sheet 1 exists 
       delay 0.1 
      end repeat 
    end tell 

    tell group "Speech" of sheet 1 of window 1 
     set checkboxOne to checkbox "Allow Player to Speak Moves" 
     set checkboxTwo to checkbox "Speak Computer Moves" 
     set checkboxThree to checkbox "Speak Human Moves" 

     tell checkboxOne 
      set checkBoxStatus to value of checkboxOne as boolean 
      if checkBoxStatus is true then click checkboxOne 
     end tell 
     tell checkboxTwo 
      set checkBoxStatus to value of checkboxTwo as boolean 
      if checkBoxStatus is true then click checkboxTwo 
     end tell 
     tell checkboxThree 
      set checkBoxStatus to value of checkboxThree as boolean 
      if checkBoxStatus is true then click checkboxThree 
     end tell 
    end tell 

    click button "OK" of sheet 1 of window 1 
end tell 

再次,自己獨立運行時,沒有錯誤。當作爲的Automator工作流/應用程序的一部分運行,我得到的錯誤:

System Events got an error: Can’t get sheet 1 of window 1 of process "Chess". Invalid index. 

與突出顯示的行是

click button "OK" of sheet 1 of window 1 

有我丟失的東西?爲什麼會發生此錯誤,我該如何解決?

在此先感謝您的幫助!

回答

0

嘗試用自己的tell語句將該部分代碼包裝延遲。像這樣:

tell application "System Events" 
    delay .2 
    click button "OK" of sheet 1 of window 1 
end tell 
+0

完美!我現在意識到遊戲中心登錄確認正在影響工作表的方式,導致錯誤。 – Red5Seeker7

0

也許你可以試試這段代碼。它會切換複選框狀態。

tell group "Speech" of sheet 1 of window 1 
    tell checkbox 1 
     perform action "AXPress" 
    end tell 
end tell 
+0

我不想這樣做的原因是,無論複選框的當前狀態如何,我都希望將其切換爲_off_,而不僅僅是反轉它。 – Red5Seeker7