Is it possible to set focus to an open textEditor? In other words set the activeEditor? Alternatively, is there a way to use the nova.workspace.openFile method to open a remote file?
I am trying to allow users to select a tag in the TODO extension and open a remote file. The openFile method works well for local projects, but unfortunately I don’t see any way to do this with a remote project.
I also needed this so here’s a quick workaround for setting the active editor:
function makeEditorActive(workspace, editor) {
const applescript = `
tell application "System Events" to tell process "Nova"
set frontmost to true
tell menu "Window" of menu bar 1
set theSepCount to 0
set correctWorkspace to false
set theIndex to 0
repeat with theItem in every menu item
set theIndex to theIndex + 1
if not (exists name of theItem) then
set theSepCount to theSepCount + 1
set checkedWorkspace to false
else if theSepCount >= 5 then
if not checkedWorkspace then
set correctWorkspace to (name of theItem = "${nova.path.basename(workspace.path)}")
set checkedWorkspace to true
else if correctWorkspace then
if name of theItem is "${nova.path.basename(editor.document.path)}" then
click menu item theIndex
exit repeat
end if
end if
end if
end repeat
end tell
click menu "Window" of menu bar 1
end tell
`;
let options = {args: [], stdio: "ignore"};
for (const line of applescript.split("\n")) {
const trimmed = line.trim();
if (trimmed != "") options.args.push("-e", trimmed);
}
let p = new Process("/usr/bin/osascript", options);
p.start();
}
This uses AppleScript to search the Window menu for the correct menu item and click it. Requires enabling Accessibility for Nova in the Security and Privacy System Preferences (it will prompt you to do it). Sadly it’s quite slow, but better than nothing.
I am not entirely sure why I need to issue a click to the Window menu itself at the end. If I omit it, the click only resolves when the user clicks on the Window menu afterwards. May be related to Nova rebuilding the menu or something.