我的脚本从 AppA 获取一些文本并将其粘贴到 AppB 上的文本编辑中。当 AppB 启动(通过脚本)时,文本编辑被禁用,当用户执行操作时变为启用。该操作需要保持手动。
该脚本在用户有时间做任何事情之前执行,这是一个错误。我的想法是检查是否启用了编辑,但这会产生此错误。“无法获取应用程序“系统事件”的<>“AppB”的AppB窗口。它只抛出一次错误。
我怎样才能避免错误?尝试阻止只是吃错误会更好吗?
on idle
tell application "System Events" to set AppAIsOpen to (application process "AppA" exists)
if (AppAIsOpen) then
set AppAWasOpen to true
tell application "AppA"
set hdg to TxRprt
set beam to hdg as string
end tell
if ((count beam) < 3) then set beam to text -3 thru -1 of ("000" & beam)
if (beam is not previousText) then
tell application "AppB" to launch
tell application "System Events"
tell application process "AppB"
if text field 1 of window "AppB" is enabled then -- error here
set value of text field 1 of window "AppB" to beam --or here
end if
end tell
end tell
set previousText to beam
end if
return checkInterval
else if (AppAgWasOpen) then
quit
return 1
end if
结束空闲