Testing in Script Editor with the language selector at top left set to JavaScript (rather than AppleScript) suggests that you could use an Execute JavaScript for Automation action.
(() => {
"use strict";
const operaWin = Application("Opera").windows.at(0);
return operaWin.exists()
? (() => {
const tab = operaWin.tabs.at(0);
return tab.exists()
? `[${tab.name()}](${tab.url()})`
: "No front tab found in Opera";
})()
: "No window open in Opera.";
})();
Obviously you left blank spaces for tab.name or tab.url, I tried replacing tab.url with "notion.so" with no results. Could you please elaborate what I need to do for the script to work?
I append a simple macro I am using in the Browser, maybe you can use this for example.
Instead of using it like the %FrontBowserURL% token, use a variation on @ComplexPoint's action to collect Opera's active tab's URL into a KM variable, then test that variable.
Partly because it isn't as featureful as @ComplexPoint's JXA. A more complete version would be:
tell application "Opera"
if (count of windows) > 0 then
return URL of active tab of front window
else
return "No active tab found in Opera"
end if
end tell
See the "Add additional Browsers to the Front Browser Actions, Tokens, and Functions." part of the "Preferences Set by Command Line" section of the manual for how to add Opera -- the full command is probably:
Keyboard Maestro supports Safari and Chrome as browsers, since they both offer full AppleScript support, including executing JavaScript via AppleScript.
It also supports any other browser that behaves the same way as either of them (so Safari Technology Preview, and all the variants of Chrome such as Edge, Brave, etc).
If Opera behaves like either of them, then Keyboard Maestro will support it automatically (with a minor config change that you can apply to tell Keyboard Maestro about it, and which would be incorporated in future versions of Keyboard Maestro).
But if it has its own syntax and/or incomplete support, then Keyboard Maestro wont support it and you can use whatever support it does have via AppleScript.
Bingo! Thank you so much for the ApppleScript. I've been wanting a solution for Arc web browser for quite some time. Dang, wish I had time to learn coding and scripting.