I feel that AXSelectedRows has finally beaten me into submission 🙂 After extensive research, I am stumped as to how to programmatically list the contents of AXSelectedRows; simply put, to get the selected rows of any given AXOutline.
It sounds trivial, but finding an answer has proven difficult – particularly due to the lack of online documentation (though I should probably buy a book!) Strangely, a lot of people just seem to want to programmatically select rows, instead of getting selected rows.
I am certainly close though. I have reached thus far:
set selectedRows to value of attribute "AXSelectedRows" of outline1
where outline1
is set to an AXOutline. Next:
set selectedRow to item 1 of selectedRows
This is where it becomes a little murky (after already failing to set it to row 1
instead of item 1
). I would expect selectedRow
to be of type AXRow
(or row
), but instead Automator output displays:
application "System Events"
That is, the item appears to be an instance of 'application "System Events"' – which leads me to believe that I'm overlooking something important. Having said that, I feel that I've tried every combination of value
's, attribute
's and row
's – including some type-casting.
The frustrating part is that I can actually see the contents of AXSelectedRows in the Accessibility Inspector! And so I know that it exists. As a workaround, I am using:
set selectedRows to selected of rows of outline1
However, this is certainly not preferable as I still have to loop through the entire array in order to find the 'true' values, which could have performance issues for very large lists.
Any help would be hugely appreciated!
Best Answer
I guess getting the value of AXSelectedRows is just something that has not been implemented. When I open a Finder window in list view, select two rows, and run this script:
The result is:
However you can use a whose clause to get the selected rows without using a repeat loop: