Ubuntu Forums Archive Viewer

[SOLVED] Running App from firefox in Ubuntu

Archived thread 2016376 from Ubuntu Application Development. Markdown source: Ubuntu_Application_Development/thread_2016376_[SOLVED]_Running_App_from_firefox_in_Ubuntu.md

Original URL About this archive
#1

Dear friends I need to make a program that opens the current local html file in gedit. I have found some code to run a local application from your firefox browser. but the problem is that this code is written for windows. I have changed the code still it does not work for me. I put the code here. please help me correct the code:

[HTML]<html> <head> </head> <body> <p/><input type="button" width="15" value="Run Exe" onclick="RunGEdit();"/></input></p>

<script type="text/javascript"> function RunGEdit() { if(navigator.userAgent.indexOf("Firefox") == -1) { alert("Currently active folder links supported only for Mozilla Firefox web browser"); return; } netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect"); var localFile = Components.classes["@mozilla.org/file/local;1"] .createInstance(Components.interfaces.nsILocalFile); var env = Components.classes["@mozilla.org/process/environment;1"] .createInstance(Components.interfaces.nsIEnvironment); localFile.initWithPath("/usr/bin/gedit"); var process = Components.classes["@mozilla.org/process/util;1"] .createInstance(Components.interfaces.nsIProcess); process.init(localFile); process.run(false, document.URL, 1);

} </script> </body> </html>[/HTML]

#2

even though with a lot of trouble, finally i found the answer:

function RunGEdit()
{
    netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
    var exe = Components.classes['@mozilla.org/file/local;1'].createInstance(Components.interfaces.nsILocalFile);
    exe.initWithPath("/usr/bin/gedit");
    var run = Components.classes['@mozilla.org/process/util;1'].createInstance(Components.interfaces.nsIProcess);
    run.init(exe);        
    var parameters = [document.URL];
    run.run(true, parameters,parameters.length);
}