BIKE Outliner – Focus on selected line, creating new tab

A macro for Jesse Grosjean's Bike Outliner.


BIKE – Focus on selected line, creating new tab

BIKE – Focus on selected line- creating new tab.kmmacros (25 KB)


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

    // New Bike app tab focused on selected row.

    // Rob Trew @2022
    // Ver 0.01

    // main :: IO ()
    const main = () => {
        const
            bike = Application("Bike"),
            doc = bike.documents.at(0);

        return doc.exists() ? (() => {
            const
                rows = doc.rows.where({
                    _and: [
                        {selected: true},
                        {_not: [{
                            name: ""
                        }]}
                    ]
                });

            return 0 < rows.length ? (() => {
                const selectedRowID = rows.at(0).id();

                return (
                    bike.activate(),
                    bundleMenuItemClicked(
                        "com.hogbaysoftware.Bike"
                    )(["File", "New Tab"]) ? (() => {
                            const
                                tabDoc = bike.windows.at(0)
                                .document();

                            return Boolean(
                                tabDoc.focusedRow = tabDoc
                                .rows.byId(selectedRowID)
                            );
                        })() : "Menu item not clicked."
                );
            })() : "No line of text selected.";
        })() : "No documents open in Bike";
    };

    // --------------------- GENERIC ---------------------

    // bundleMenuItemClicked :: String -> [String] -> IO Bool
    const bundleMenuItemClicked = bundleID =>
        menuPath => {
        // True if an item at the specified menu path
        // has been successfully clicked in an
        // application with the given bundle identifier.
            const intMenuPath = menuPath.length;

            return intMenuPath > 1 ? (() => {
                const
                    appProcs = Application("System Events")
                    .processes.where({
                        bundleIdentifier: bundleID
                    });

                return 0 < appProcs.length ? (
                    Application(bundleID)
                    .activate(),
                    menuPath.slice(1, -1).reduce(
                        (a, x) => a.menuItems[x].menus[x],
                        appProcs[0].menuBars[0].menus
                        .byName(menuPath[0])
                    )
                    .menuItems[menuPath[intMenuPath - 1]]
                    .click(),
                    true
                ) : false;
            })() : false;
        };

    // MAIN ---
    return main();
})();

Other Keyboard Maestro macros for BIKE Outliner

2 Likes

Thanks! This will be a very useful macro for me ... though I never thought of it before.

1 Like

Problem...

Screenshot 2023-02-07 alle 12.47.27

If Italian is a problem let me know...

Have you tried running it as a Keyboard Maestro macro, rather than from Script Editor ?

(It looks as if you haven't yet granted assistive access permissions to Script Editor)


See, for example:
macos - "is not allowed for assistive access" error when running AppleScript Stack Overflow

1 Like

thanks!