Opening path in browser or external app

I am trying to open an arbitrary path in an external browser (from JavaScript). I tried:

ko.browse.openUrlInDefaultBrowser(uri);

But this seems to work only if uri is a standard protocol (http, ftp, …). My protocol is “thunderlink://…”.

I also tried by directly calling an external app, like Firefox, from the JavaScript code, but I cannot find the way to make it work (maybe it is not possible to call an external program?). I tried using komodo.runCommand(), also with doCommand(…), and even with open(…), but with no success.

My final purpose is to be able to open a Thunderbird email from Komodo Edit, whose link has been obtained by using Thunderlink (https://addons.mozilla.org/es/thunderbird/addon/thunderlink/). This implies loading Firefox (or directly Thunderbird) with a URI that looks like thunderlink://… I want to do it with a Komodo Edit’s script in JavaScript to automate the opening of some links from the editor. This would be very useful.

Thank you very much for any tip!

If you’re under linux, you can use xdg-open. (since the instruction on the add-on page says that you have to register a xdg handler) to open these links. You can invoke it with require('ko/shell').run('xdg-open', ['your_url']). I believe you can invoke thunderbird in the same way:

require(`ko/shell`).run('thunderbird', ['-thunderlink', 'thunderlink://...'])

I think it’d be easier just to create a command through your toolbox, no sense using a userscript for this.

Uhh I forgot about them. That’s a good idea!

Thank you for all the suggestions. Regarding the option 1, unfortunately I use Windows: is there any alternative solution for Windows?

Regarding the option 2, I am not sure about what you mean. Could you please clarify it? Maybe the proposed solution is not applicable for my specific case, but I am not sure. What I want to do is to be able to select a thunderlink hyperlink in Komodo Edit, to open the link in Firefox or Thunderbird. For this, I intend to use the proposed solution at http://docs.activestate.com/komodo/7.0/hyperlinks.html (section “Custom”, about the PEPRegexHandler). The function to call should be the one I am trying to implement now, that I call “test”:

function test(theStringOriginal, theStringReplacement)
{
ko.browse.openUrlInDefaultBrowser(theStringReplacement);
}

(this one does not work if theStringReplacement is a URI with a protocol different from the typical ones: http, ftp, etc.)

Thank you for any idea.

Yes, it’s in my post, second code example. Just find the path to the thunderbird binary.

Here’s an example macro that will register a handler for thunderlink links.

let Ci = Components.interfaces;
let RGB = (r, g, b) => r + g * 256 + b * 256 * 256;
let thunderlinkHandler = new ko.hyperlinks.RegexHandler(
    "Thunderlink handler",
    /(thunderlink:[^\s]+)/,
    (original, replacement) => {
        require('ko/shell').run('C:\\path\\to\\thunderbird.exe', ['-thunderlink', replacement]);
    },
    "$1",
    null,
    Ci.ISciMoz.INDIC_PLAIN,
    RGB(0x60, 0x90, 0xff)
);
let handler = ko.hyperlinks.getHandlerWithName("Thunderlink handler");
while (handler !== null) {
    ko.hyperlinks.removeHandler(handler); // remove existing handlers just in case
    handler = ko.hyperlinks.getHandlerWithName("Thunderlink handler");
}
ko.hyperlinks.addHandler(thunderlinkHandler);

This should work.

1 Like

Thanks a lot, this works perfectly! (just maybe a little slow when calling Thunderbird.exe).

Best regards.