jxa: openlocation x-callback not working correctly

I have a touch bar button with a run jxa action and the code below to paste clipboard contents into Bear notes using a Bear x-callback. It runs ok but only calls the x-callback once, working again if I edit and save the script. Any ideas?


let app = Application.currentApplication();
app.includeStandardAdditions = true

let url = "bear://x-callback-url"
let action = 'create'
let text = encodeURIComponent( app.theClipboard() )

let call = `${url}/${action}?text=${text}`


app.openLocation( call )

app.displayNotification("Pasted to Bear.")


Weird but probably nothing BTT can fix as it just executes the JXA (on editing it is recompiled, maybe that's allowing it to run again but is not a good general solution).

Would it be possible to use the "run real javascript" action instead?

(async () => {

let clipboardContents = await runShellScript({
    script: 'pbpaste'
});

let url = "bear://x-callback-url"
let action = 'create'
let text = encodeURIComponent(clipboardContents)
let call = `${url}/${action}?text=${text}`


await runShellScript({
    script: `open "${call}"`
});

await runShellScript({
    script: `osascript -e 'display notification "Pasted to Bear"'`
});

returnToBTT(call);

})();

That seems to work, thanks Andreas.

FWIW, it has the feel of something not being flushed or closed. Also, run in the Apple script editor, it always runs.

K.

The script editor also always recompiles the script. The scripting frameworks don't give us any way to flush or not flush / complete anything as far as I know.

Maybe I should add an option to recompile all the time, but in general it wastes a lot of CPU.

Imprint | Privacy Policy