我有一个涉及一些 UI 脚本的脚本,用于在不支持 applescript 的内部应用程序中定位电话号码(因此我必须使用 UI 脚本)。我写成功的部分如下:
tell application "System Events" to set frontmost of process "Ticket Tracker" to true
tell application "System Events"
tell process "Ticket Tracker"
try
try
set the_number to value of attribute "AXvalue" of static text 14 of group 1
of scroll area 1 of splitter group 2 of splitter group 1 of window 1
if the_number = "" then
set the_number to value of attribute "AXvalue" of static text 1 of
splitter group 1 of window 1
end if
on error
set the_number to value of attribute "AXvalue" of combo box 3 of
tab group 1 of scroll area 1 of splitter group 2 of splitter group 2 of
splitter group 1 of window 1
if the_number = "" then
set the_number to value of attribute "AXvalue" of static text 11
of tab group 1 of scroll area 1 of splitter group 2 of splitter group 2
of splitter group 1 of window 1
end if
end try
这段代码的后半部分是尝试从第二个新打开的窗口中获取数字。当第一个窗口打开并且是您要从中获取数字的窗口时,“窗口 1”是一个非常好的索引。但是如果您打开一个新窗口,而您的第二个窗口(打开的第一个窗口)是您要从中获取号码的窗口,那么您必须寻找“窗口 2”,这就是我合并第一段代码的原因如您所见,将第二个与尝试和错误绑定在一起...
on error
try
set the_number to value of attribute "AXvalue" of static text 14
of group 1 of scroll area 1 of splitter group 2 of splitter group 1
of window 2
if the_number = "" then
set the_number to value of attribute "AXvalue" of static text 1
of splitter group 1 of window 2
end if
on error
set the_number to value of attribute "AXvalue" of combo box 3 of
tab group 1 of scroll area 1 of splitter group 2 of splitter group 2
of splitter group 1 of window 2
if the_number = "" then
set the_number to value of attribute "AXvalue" of static text 11
of tab group 1 of scroll area 1 of splitter group 2 of splitter group 2
of splitter group 1 of window 2
end if
end try
end try
end tell
end tell
这是一个很好的入门概念,但是使用我的脚本的其他人以不同的方式操作“Ticket Tracker”应用程序,并要求我搜索高达 6 或 7 的“窗口索引”。
我想要做的是编写一个脚本对象,它使用我拥有的代码块的前半部分,然后如果找不到“window x”尝试找到“window x + 1”并继续尝试直到成功(限制为 20 左右)。我对脚本对象非常陌生,并且仍在尝试掌握这个概念,但这是我到目前为止所拥有的:
Script indexFinder
property x : 1
to tryAgain
set x to x + 1
try
try
set the_number to value of attribute "AXvalue" of static text 14 of group 1
of scroll area 1 of splitter group 2 of splitter group 1 of window x
if the_number = "" then
set the_number to value of attribute "AXvalue" of static text 1 of
splitter group 1 of window x
end if
on error
set the_number to value of attribute "AXvalue" of combo box 3 of
tab group 1 of scroll area 1 of splitter group 2 of splitter group 2 of
splitter group 1 of window x
if the_number = "" then
set the_number to value of attribute "AXvalue" of static text 11
of tab group 1 of scroll area 1 of splitter group 2 of splitter group 2
of splitter group 1 of window x
end if
end try
on error
repeat tryAgain
end try
end tryAgain
end script
我不确定这种语法是否正确,但我认为它封装了我想要完成的事情。谢谢大家的帮助。