2017-07-17 64 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