AppleScript启用编辑框
问题描述:
我的脚本从AppA获取一些文本并将其粘贴到AppB上的文本编辑中。当AppB启动时(通过脚本),文本编辑被禁用,当用户执行操作时变为启用状态。该行动需要保持手动。AppleScript启用编辑框
该脚本在用户有时间处理任何事情之前执行错误。我的想法是检查是否启用了编辑,但是出现此错误。 “无法获得应用程序”系统事件“的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
结束闲置
答
通常我进入一个重复循环并为您的文本字段(或任何界面元素),试图用它做任何事情之前变得可用。这样的事情会工作,并应消除你的错误
不是冰我也加入了一个时间检查这个过程,以便我不会陷入重复循环。在这种情况下,我最多等待5秒以使文本字段可用。
tell application "System Events"
-- wait for the text field to become available
set startTime to current date
repeat until exists (text field 1 of window "AppB" of application process "AppB")
if (current date) - startTime is greater than 5 then
error "Could not find text field 1 of window AppB of application process AppB"
exit repeat
end if
delay 0.2
end repeat
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
这很好用。谢谢。 – Mike 2013-02-25 03:21:46