Keyboard shortcut for jumping to first or last item in outline?

Do keyboard shortcuts exist for jumping to (selecting) the first or last items in an outline?

Maybe I’m an outlier, but I find myself having to jump to the end of an outline quite often, and sometimes to the top of an outline too. So far I haven’t figured out how to do that with the keyboard…

Can’t immediately find anything in the help file – no obvious sight of a clean graphic table of keystrokes in there, though there’s a long stretch of verbal material.

If nothing comes to light, you can attach a script like this to a keystroke with something like FastScripts or Keyboard Maestro:

(function() {
    'use strict';
    
    // Toggle selection between last and first row
    
    var oo = Application("com.omnigroup.OmniOutliner4"),
        ds = oo.documents,
        d = ds.length ? ds[0] : undefined;
        
    if (d) {
        var rows = d.rows,
            rowLast = rows.at(-1);
        
        if (!oo.frontmost()) oo.activate();
        
        oo.select(
            rows.at(
                d.selectedRows.at(0).id() === rowLast.id() ? 0 : -1
            )
        );
    }   
})(); 
2 Likes

Thank you for that fantastically helpful reply. I’m already a Keyboard Maestro user and I know JavaScript, so this was just perfect and exactly what I needed to point me in the right direction :-).

One thing worth noting is that while the code selects a row, the OO document doesn’t end up getting scrolled to the top or bottom. (Does it for you? Maybe it’s due to something quirky about my environment.) It was easy to fix by adding a keystroke to type Home or End as part of the macro in Keyboard Maestro.

Good addition.

( I had only tested it with a tiny document – failure of imagination on my part :-)

Keyboard Maestro is probably the best source of the Home/End keystroke – it takes care of the low level details, like waiting for the application to be ready to receive a keystroke.

Directly from script, it seems (at least on my system) to need a delay, which might need adjusting on other systems.

(function () {
    'use strict';

    // Toggle selection between last and first row

    var oo = Application("com.omnigroup.OmniOutliner4"),
        ds = oo.documents,
        d = ds.length ? ds[0] : undefined;

    if (d) {
        var rows = d.rows,
            seln = d.selectedRows.at(0),
            blnAtEnd = seln.id() === rows.at(-1)
            .id();

        var se = Application("System Events"),
            home = 115,
            end = 119;

        oo.select(
            rows.at(
                blnAtEnd ? 0 : -1
            )
        );
        
        if (!oo.frontmost()) oo.activate();
        delay(0.1)
        se.keyCode(blnAtEnd ? home : end);
    }
})();
1 Like