Reputation: 229
I have looked at the following questions that were answered here:
How to open file in Mozilla Add-on SDK using system default application
How can I open an external app from Firefox addon? (Eg: default text editor)
Perfom a ShellExecute from Firefox Addon
yet none of these solutions have worked for me and I feel the problem may be deeper than I originally thought. Essentially I am trying to launch a .jar executable with a Mozilla add-on extension. My code looks like the following:
var buttons = require('sdk/ui/button/action');
var button = buttons.ActionButton({
id: "execute-jar",
label: "Download Report",
icon: {
"16": "./icon-16.png",
"32": "./icon-32.png",
"64": "./icon-64.png"
},
onClick: handleClick
});
function handleClick(state) {
// try {
// var file = Services.dirsvc.get("Desk", Ci.nsIFile);
// file.append("C:\Users\QaziWa\DownloadReportPPE.jar");
// file.launch();
// }
// catch (ex) {
// console.error("failure");
// Failed to launch because e.g. the OS returned an error
// or the file does not exist,
// or this function is simply not implemented for a particular platform.
// }
let {Cc, Ci} = require('chrome');
var file = Cc["@mozilla.org/file/local;1"].createInstance(Ci.nsILocalFile);
file.initWithPath("C:\Users\QaziWa\DownloadReportPPE.jar");
console.log(file);
if(file.exists()){
file.reveal();
file.launch();
}
else {
console.log('Failed.');
}
}
For some odd reason my .jar file is not detected and I can't understand why. I was hoping someone could offer any input as to why this may be.
Upvotes: 1
Views: 364
Reputation: 37238
Change
file.initWithPath("C:\Users\QaziWa\DownloadReportPPE.jar");
to
file.initWithPath("C:\\Users\\QaziWa\\DownloadReportPPE.jar");
Need to escape those slashes ;)
Upvotes: 1