Search code examples
applescriptnsoutlineview

How to access the text of a particular row of an outline control with AppleScript?


I'm trying to select a particular row of an outline using AppleScript, based on its text.

Here's what I'm considering (but doesn't work):

repeat with aRow in rows of outline 1 of scroll area 1 of splitter group 1 of window 1
    set t to text of cell of aRow
    if t starts with "some text" then select aRow
end repeat

The problem is that text of cell of aRow doesn't resolve to what I think it should. I've used the Accessibility Inspector to confirm the object hierarchy. I've tried using "UI Elements" on the row to see what elements are accessible, but it doesn't return anything useful. So I'm out of idea! What am I missing?


Solution

  • With @markhunte's hint, I worked out how to reach the text of a row in the outline, using UI Elements and get properties. It turns out the AXRow > AXCell > AXStaticTexthierarchy displayed by the Accessibility Inspector was misleading.

    The text of each is access through name of first UI Element of row (of outline...).

    Here's the working code that does what I intended to achieve:

    tell application "System Events"
        tell process "MyApp"
    
            repeat with aRow in row of outline 1 of scroll area 1 of splitter group 1 of window 1
                if name of first UI element of aRow starts with "Schedule" then select aRow
            end repeat
    
        end tel
    end tell