For quite some time now I have been looking for a solution to get around skipping the "Top Hits" section on Mac Mail message list section that some times appears when searching for a usual search term. However, since this search result grouping does consistently appear and the resulting list varies in size due to the count of messages found, it is rather difficult to create some type macro to skip it and go directly to actual search results.
That being said, using UI Browser I have been able to determine that the search results are generated into a table and Mail actually makes one of the table rows into the usual "Sort by..." bar that appears on top when the "Top Hits" aren't shown. This normally not being the case when "Top Hits" aren't provided. Considering this, I was wondering if, with AppleScript, it would be possible to determine the row the "Sort by..." bar is located on the results and then focus on it?
I have tried "click menu button 1 of UI element 1 of row 110 of table 1" and it works. However, the view of the button does not come into focus, causing the resulting button menu to just randomly appear, and in this case the row number is specific which should not be the case since the search results will vary the row number.
Essentially I would just like the script to determine in which row the "Sort by..." is residing and then select the message row that occurs after it.
I hope someone is able to help.
Thanks in advance.
As an update, I have discovered that I can parse out the email message rows from the non email message rows (header row such as "Top Hits") using the following AppleScript. However, since I am not fluent with AppleScript I am having trouble figuring out on how to pull the row number of the rows that return "false", the non email message rows. Anyone familiar with such a process?
tell application "System Events"
tell application process "Mail"
set frontmost to true
tell (first window whose attribute "AXRoleDescription"'s value is "standard window")
tell scroll area 1 of splitter group 1 of splitter group 1
tell table 1
if focused is false then set focused to true
repeat with R in rows
if static text 1 of UI element 1 of R exists then
log true
end if
end repeat
end tell
end tell
end tell
end tell
end tell
Update 2
Have been able to achieve what I originally intended but unfortunately it appears that although the appropriate email message is select at the end of script the viewer does not focus on the message. For now, I have been able to work around it by pressing the up arrow and then again the down arrow on the keyboard to bring the message into focus. Any suggestions on how this can be achieved within the script but without using keystroke commands?
tell application "System Events"
tell application process "Mail"
set frontmost to true
tell (first window whose attribute "AXRoleDescription"'s value is "standard window")
tell scroll area 1 of splitter group 1 of splitter group 1
tell table 1
if focused is false then set focused to true
set RowCount to count of rows
repeat with theIncrementValue from 1 to RowCount
if not (static text 1 of UI element 1 of row theIncrementValue exists) then
select row (theIncrementValue + 1)
exit repeat
end if
end repeat
end tell
end tell
end tell
end tell
end tell