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 = () => {
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();
})();
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"
activate
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
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!