How to have one keybind for both `collapse` and `expand`

I am struggling to do it.

I see there is cmd+9 for collapse and cmd+0 for expand. I need one keybind for collapse (if i can), expand (if I can).

Bike 1, or Bike 2 preview ?

If Bike 1, then perhaps, in AppleScript terms, something like:

tell application "/Applications/Bike.app"
    tell front document
        if it exists then
            tell (rows where selected = true)
                tell item 1
                    if it exists then
                        if (collapsed of it) then
                            expand with all
                            "Expanded"
                        else
                            collapse with all
                            "Collapsed"
                        end if
                    else
                        "Nothing selected in Bike front document"
                    end if
                end tell
            end tell
        else
            "No document open in Bike"
        end if
    end tell
end tell

or in Bike 1 JavaScript for Automation, perhaps:

Expand disclosure triangle to view JS source
(() => {
    "use strict";

    // Full expansion / contraction of all descendants ?
    const allExpand = true;
    const allContract = false;

    const
        bike = Application("/Applications/Bike.app"),
        doc = bike.documents.at(0);

    return doc.exists()
        ? (() => {
            const
                selnRows = doc.rows.where({ selected: true }),
                firstSelnRow = selnRows.at(0);

            return firstSelnRow.exists()
                ? firstSelnRow.collapsed()
                    ? (
                        bike.expand(selnRows(), { all: allExpand }),
                        "Expanded"
                    )
                    : (
                        bike.collapse(selnRows(), { all: allContract }),
                        "Collapsed"
                    )
                : "Nothing selected in Bike front document."
        })()
        : "No document open in Bike"
})();

yea bike 1

applescript worked (although with slight delay, i wish it would be instant)

and jxa thing did not work at all, threw error

This is working here (Keyboard Maestro ‘modern syntax’, no variables, notify results):

Toggle Collapse (Bike 1).kmmacros.zip (1.8 KB)


This kind of customisation is much faster in Bike 2 previews, incidentally – the JavaScript interpreter is part of the application itself, bypassing the delays of the Apple Events interface.

1 Like