Script: Selection row focus in new window

Update in 2022-12-17
improved the KM macro, now maybe it’s the fastest way.


global bikeurl

tell front document of application "Bike"
	set bikeurl to URL of selection row
end tell

tell application "System Events"
	tell process "Bike"
		click menu item "New Window" of menu "File" of menu bar 1
	end tell
end tell

tell front document of application "Bike"
	open location bikeurl
end tell

Not sure if it’s just my system (macOS 11.7) but the focus seems to be opening in the existing (rather than new) window.

Perhaps a variant approach (to side-step any saving / versioning issues associated with a new document window) might be to create a new tab for the focus instead ?

Possibly something like:

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 = () => {
            bike = Application("Bike"),
            doc =;

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

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

                return (
                    )(["File", "New Tab"]) ? (() => {
                                tabDoc =

                            return Boolean(
                                tabDoc.focusedRow = tabDoc
                        })() : "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 ? (() => {
                    appProcs = Application("System Events")
                        bundleIdentifier: bundleID

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

    // MAIN ---
    return main();

I’m not sure what’s going on, it’s works well here. <macOS 12.6, Bike 1.5(87)>

2022-10-25 18_56_32

Could be that I have just misunderstood the goal – you end up with the same document open in two different windows ?

( Perhaps more likely to be a timing issue here )

OK, works here if we add a brief delay to ensure that front document is already bound to the document of the new window.

tell application "Bike"
    set bikeurl to URL of selection row of front document
    tell application "System Events"
        tell process "Bike" to click menu item ¬
            "New Window" of menu "File" of menu bar 1
    end tell
    delay 0.1
    tell front document to open location bikeurl
end tell

Yes, it’s just timing issue, perhaps.

When I have a document like Moby Dick, and when I want to focus in Chapter 130 paragraph 4 in new window, it will save my time.

thank you!


Improved the KM macro.
Focus in new window.kmmacros


Thanks so much for this macro! At first I thought it would be irrelevant to my usage. But I’m testing it out today and find it very useful for a new long Bike document I’m working on. Really appreciate all those who amplify the power of Bike through macros!


With the Bike v1.9 update, the previous macro is not working anymore.

Please change second action (Select Menu Item in Bike) to this:
Window ⇢ Duplicate Tab to New Window

or just download the new macro
Focus in new window 1.1.kmmacros

1 Like