I have a script that involves some UI Scripting to target a phone number in an in-house application that does not support applescript (thus why I must UI Script). The part which I have successfully written is as follows:
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
The second half of this code is to try and grab the number from the 2nd newly opened window. When the first window is opened and that is the window you want to grab the number from, then “window 1” is a perfectly fine index. But if you open a new window, and your second window (the first one opened) is the one you want to grab the number from, then you have to look for “window 2”, that is why I combined the first block of code with the second and tied it together with try and on error as you can see…
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
This was a good starter concept, however other people who would use my script operate the “Ticket Tracker” application differently and would require me to search for “window indexes” as high as 6 or 7.
What I want to do is write a script object that uses the first half of the block of code that I have, and then if it fails to find “window x” to try to find “window x + 1” and to continue to try until it succeeds (with a limit of about 20). I am very new to script objects and still trying to grasp the concept but this is what I have so far:
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
I’m not sure if this syntax is correct but I think it encapsulates what I’m trying to accomplish. Thank you for all the help.
You can try something like this: