Hey guys,
I have a work app that has a list employees when you search for a name. If you search for a manager’s name it will show you the manager, the employees that report to that manager, and the manager’s direct reports. So if I search for Bob Smith, I would see Bob Smith, Bob Smith (direct reports), and all the numerous employee names that report to bob smith individually.
I’m trying to make a script that will find the Bob Smith (direct reports) and choose it for me. I’m doing this for multiple managers. So far, I have it working by searching for the name. Then I hard coded how many times to press the down arrow before pressing return. But the manager lists can change weekly, so the number of down arrow presses changes frequently. So now I’m trying to find a more reliable way to always choose the direct reports choice I need.
The commonality I’ve found is that there is a UI image (always called image 1) next to the direct report row I need. It is the only thing in the table that has an image like that. So if I can find the row with that image in it, then I can set the number of down arrow presses equal to that row’s number and 100% choose direct reports.
What I can’t seem to figure out is the repeat logic. I want it to try to select the image in row 1; if it can’t and errors then try row 1+1, then row 2+1, then 3+1, etc down the line until it can select the image. When it eventually does select it, tell me the final row number that was used.
In it’s current form it’s getting stuck in an infinite loop. Any help would be greatly appreciated.
tell application "System Events"
tell process "Work Manager"
set frontmost to true
set rowNumber to 1
set x to true
repeat while x is true
try
select image 1 of UI element 1 of row rowNumber of table 1 of scroll area 1 of window 1 --select the image next to the direct reports
set x to false
on error
rowNumber + 1
end try
end repeat
end tell
end tell