AppleScript UI Scripting: Scroll Row to Top of Visible View in Final Cut Pro?

@ccstone - Chris (or whoever), this isn't high priority, but I wondered if you knew how to do it. Let's say I have this scrollable table in Final Cut:

image

I'd like to scroll the selected row to the top of the view. The path to the element is typical:

... row 68 of table 1 of scroll area 1 ...

I know how to get/set the scroll position, get the bounds of stuff, etc, and I might be able to calculate the desired scroll position based on the bounds, but I was wondering if there's an easy way to do it. Like a "scroll to top" action.

If you don't know off the top of your head, don't spend too much time on it. It would only be a very minor improvement to my workflow, and while even minor improvements are nice, it's certainly not something to waste too much time on.

Thanks!

Hi, Dan

I did something similar to scroll to a particular row in the Keyboard pref pane's text substitutions - effectively:

set matchedRow to (row 1 ...)
-- Select the row, then move the cursor up and back down to scroll to it
select matchedRow
key code 126
key code 125

Jiggling the cursor keys seems a bit lame ... but it worked! (You may need to swap the order to down then up for the first row, I guess). I'd be interested to know if there was a better way :slight_smile:

Best wishes,
Steve

Thanks, Steve. I'm guessing in your case, the selected row wasn't coming into view at all (or perhaps partially), right? In my case, I just want to move the selected row to the top of the view area, so I can see as many rows after it as possible.

Yes, it was exactly that! (As the 'yy-'' expansion was at the bottom of the list)

If you were to select the row you want, could you cursor down enough to scroll it to where you want the row to be, and then cursor back up? If it works, it should happen in a split second…

That's an interesting idea. Yes, the down and up-arrows happen fast enough that might be feasible. And the Table UI element has a property something like "VisibleRows", so it's definitely possible.

I'm going to see if I can do the calculations necessary to manipulate the scroll bar. I mean, I already know how to change the scroll bar, so if I can just figure out the calculations... We'll see.

Hey Dan,

I'll be surprised if you find enough precise data in AXVisibleRows to do your calculation, but please let us know if you develop a working solution.

The brute-force method would be to select your row, page down and then arrow-down, arrow-up.

-Chris

1 Like

Hey Dan, I'm not sure I fully understand your requirement.
Do you want to scroll to:

  1. Top of Current Window
    OR
  2. Top of the entire List?

I assume you know the standard macOS shortcut, ⌥↑ to go to the top of a List.

I've never seen an AppleScript "scroll to top" action, unless the app developer specifically provides for it.

So I would expect that you will have to do it the more complicated way that you outlined.

I don't know if this will help, but FWIW here is how I handled a similar situation with MS Outlook 365 scrolling.

AppleScript to Get Scroll Bar Position to Click

property ptyScriptName : "Get OL Scroll Bar Position Just Below Scroll Button"
property ptyScriptVer : "1.0"
property ptyScriptDate : "2021-04-27"
property ptyScriptAuthor : "JMichaelTX"

activate application "Microsoft Outlook"

tell application "System Events"
  tell process "Microsoft Outlook"
    
    set winList to its windows
    set oWin to item 1 of winList
    
    try
      tell oWin
        tell value indicator 1 of scroll bar 1 of scroll area 1 of splitter group 1 of splitter group 1 of splitter group 1
          
          set {xPosition, yPosition} to position
          set {xSize, ySize} to size
          set {posX, posY} to {xPosition, yPosition}
          set {sizeX, sizeY} to {xSize, ySize}
        end tell
        set clickAt to {xPosition + (xSize div 2), yPosition + (ySize + 10)}
      end tell -- oWin
      
    end try
    
  end tell
end tell

return clickAt

Simple Macro To Use that Position

image

HTH.

I have a row that's selected, and I want that row scrolled to the top of the visible rows. I don't want the row's position in the list changed, I just want it to be the first row I can see. That way, I can see more of the rows below the selected row.

I've seen the action "Scroll Into View" with an optional parameter to say whether to put it at the top, middle, or bottom of the visible items, in certain frameworks, so that's what I was hoping for here, but apparently not.

It turns out that I'm not smart enough to calculate the correct scroll bar position. And "AXVisibleRows" isn't behaving itself (in JXA).

I can probably figure it out from the row's bounds, but honestly, it's not worth the effort right now.