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!


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:

tell application "System Events" to tell window 1 of process "Finder"
    value of attribute "AXSelectedRows" of outline 1 of scroll area 1 of splitter group 1
end tell

The result is:

{application "System Events", application "System Events"}

However you can use a whose clause to get the selected rows without using a repeat loop:

tell application "System Events" to tell process "Finder"
    rows of outline 1 of scroll area 1 of splitter group 1 of window 1 where selected is true
end tell
  • Thank you for investigating this, Lri. Your suggestion works a treat!...while also being efficient. I'd be surprised if it has not been implemented though - I believe it is more likely to be a bug in AppleScript. According to Apple's own documentation (developer.apple.com/library/Mac/documentation/…), AXSelectedRows should return an array - and therefore the bug would be that they forgot to implement it :) Either way, you've satisfactorily answered the question! – user63136 Nov 22 '13 at 19:25

You must log in to answer this question.