Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save Noitidart/730edc0d3517483b5100 to your computer and use it in GitHub Desktop.
Save Noitidart/730edc0d3517483b5100 to your computer and use it in GitHub Desktop.
_ff-addon-snippet-NsiProcessNoPidPollution - On Mac to prevent PID pollution when launching other files, the solution was to use /usr/bin/open
console.time('nsIProcess runAsync');
var open = new FileUtils.File('/usr/bin/open', []);
var process = Cc['@mozilla.org/process/util;1'].createInstance(Ci.nsIProcess);
process.init(open);
var args = ['-a', '/Users/noit/Library/Application Support/Firefox/profilist_data/profile_launchers/Firefox - cust.app'];
/*
if (url) {
if (OS.Constants.Sys.Name != 'WINNT') {
args.push('--args'); //for /usr/bin/open for nix/mac
}
args.push('about:home');
args.push(url);
}
*/
var cb = function(s, t, d) {
console.info('s:', s, 't:', t, 'd:', d);
console.timeEnd('nsIProcess runAsync');
if (s.exitValue == 0) {
console.log('succesfully launched');
} else if (s.exitValue == 1) {
console.warn('error 1 happend, did not launch, app may already be open');
} else {
console.warn('an exitValue other then 0 or 1 happend i havent seen this happen yet in my couple days with it');
}
}
process.runAsync(args, args.length, cb);
@Noitidart
Copy link
Author

README

Rev1

  • Works

  • Here is the run method as opposed to the runAsync method posted above

    console.time('nsIProcess run');
    var open = new FileUtils.File('/usr/bin/open', []);
    var process = Cc['@mozilla.org/process/util;1'].createInstance(Ci.nsIProcess);
    process.init(open);
    var args = ['-a', '/Users/noit/Library/Application Support/Firefox/profilist_data/profile_launchers/Firefox - cust.app/MacOS/firefox', '--args', '-P', 'cust', '-no-remote']; //-new-instance
    /*
    if (url) {
    args.push('about:home');
    args.push(url);
    }
    */
    process.run(false, args, args.length);
    console.timeEnd('nsIProcess run');
    
  • Updated description to make comments to make clear that this works or mac only, nix does not have open like this for that I had to use Gio see GitHubGIST :: Noitidart / _ff-addon-snippet-GioLaunch.js

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment