gpt4 book ai didi

firefox-addon - 如何从 Firefox 插件打开外部应用程序? (例如 : default text editor)

转载 作者:行者123 更新时间:2023-12-05 01:08:42 25 4
gpt4 key购买 nike

我需要我的插件能够使用外部工具编辑一些文件。有任何想法吗?

最佳答案

此代码段在提供路径时显示或启动文件:

var localFile = Cc["@mozilla.org/file/local;1"].createInstance(Ci.nsILocalFile);
localFile.initWithPath("C:\\some-directory\\some-file.png");

if(localFile.exists()){
// localFile.reveal(); // open the containing folder of the file
// localFile.launch(); // launch the file
}

但是,您可能需要使用 nsIProcess为了运行带有参数的可执行文件(例如您尝试使用可执行文件打开的文件路径)。
var exeFile = Cc["@mozilla.org/file/local;1"].createInstance(Ci.nsILocalFile);
exeFile.initWithPath("C:\\Program Files\\...\\app.exe");
var parameter="C:\\some-directory\\some-file.txt";
if(exeFile.exists()){
var process = Cc["@mozilla.org/process/util;1"].createInstance(Ci.nsIProcess);
process.init(exeFile);
process.run(false,[parameter],1); // launch the executable with another file as parameter.
}

文档:

https://developer.mozilla.org/en-US/docs/XPCOM_Interface_Reference/nsIFile
https://developer.mozilla.org/en-US/docs/XPCOM_Interface_Reference/nsILocalFile
https://developer.mozilla.org/en-US/docs/XPCOM_Interface_Reference/nsIProcess
https://developer.mozilla.org/en-US/docs/Code_snippets/File_I_O

关于firefox-addon - 如何从 Firefox 插件打开外部应用程序? (例如 : default text editor),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16754621/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com