Search code examples
javascriptnode.jsmacosnode-webkit

Node webkit: How to open external link with system default browser in MAC


In windows I was using these lines

gui = require('nw.gui');

//To open a website externally
gui.Shell.openExternal(URL);

//To execute command line
gui.Shell.openItem(commandString);

Its working properly. The same piece of code is not working in MAC. What am i missing here? I dont want to create any file and write commands in it (batch file, which is usually called a shell script.). Is there a way without creating batch file and run these commands in MAC?


Solution

  • Could you provide the complete portion of code you are testing ?

    The following snippet works fine on OSX (tested with nw.js 0.12.0):

    var gui = require('nw.gui');
    gui.Shell.openExternal('http://www.google.com');
    

    Also, the gui.Shell.openItem command is not made to execute commands (see the Shell documentation).

    You should rather use the child_process module shipped with nodejs:

    var exec = require('child_process').exec;
    exec(commandString, function (error, stdout, stderr)
    {
        console.log('stdout:' + stdout);
        console.log('stderr:' + stderr);
    });