将 AppleScript 放入工作流时工作失败
Working AppleScript fails when put into Workflow
作为前言,我非常 AppleScript 新手。
我有一个非常简单的 working AppleScript,当 运行 作为 [=35= 的一部分时,它总是失败] 在 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 中作为 Workflow/Application 的一部分时,我收到错误:
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
有什么我遗漏的吗?为什么会出现此错误,我该如何解决?
在此先感谢您的帮助!
尝试将这部分代码延迟包装在它自己的 tell 语句中。像这样:
tell application "System Events"
delay .2
click button "OK" of sheet 1 of window 1
end tell
也许你可以试试这个代码。它将切换复选框状态。
tell group "Speech" of sheet 1 of window 1
tell checkbox 1
perform action "AXPress"
end tell
end tell
作为前言,我非常 AppleScript 新手。
我有一个非常简单的 working AppleScript,当 运行 作为 [=35= 的一部分时,它总是失败] 在 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 中作为 Workflow/Application 的一部分时,我收到错误:
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
有什么我遗漏的吗?为什么会出现此错误,我该如何解决?
在此先感谢您的帮助!
尝试将这部分代码延迟包装在它自己的 tell 语句中。像这样:
tell application "System Events"
delay .2
click button "OK" of sheet 1 of window 1
end tell
也许你可以试试这个代码。它将切换复选框状态。
tell group "Speech" of sheet 1 of window 1
tell checkbox 1
perform action "AXPress"
end tell
end tell