2017-07-17 1 views
0

序文として、私は非常に AppleScriptを初めて使用しています。ワークフローに入ったときにAppleScriptが動作しない

私は、Automatorのワークフローで/アプリケーションの一部として実行するときは常に失敗する非常に単純な、作業 AppleScriptを持っています。私はスクリプトエディタ内で複数回実行でき、エラーもないので、スクリプトが動作することを知っています。単独で実行

再び
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

パーフェクト! Game Centerのサインインの確認がシートの途中になって、エラーが発生したことがわかりました。 – Red5Seeker7

0

多分あなたはこのコードを試すことができます。チェックボックスの状態を切り替えます。

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

私がこれをしたくない理由は、チェックボックスの現在の状態にかかわらず、逆転させるのではなく、オフにしたいからです。 – Red5Seeker7

関連する問題