Copy XREExeF and paste as file shortcut

前提是你 提交于 2019-12-24 12:33:33

问题


In my addon I was launching Firefox profiles by doing this:

var exe = FileUtils.getFile('XREExeF', []); //this gives path to executable
var process = Cc['@mozilla.org/process/util;1'].createInstance(Ci.nsIProcess);
process.init(exe);

var args = ['-P', profName, '-no-remote']; //-new-instance
if (url) {
    args.push('about:home');
    args.push(url);
}
process.run(false, args, args.length);

So this adds command line arguments and launches it. However this leads to some problems. Users want to pin the icon and it just pins another firefox.exe. Users also try to change the icon.

Wikipedia says all OS support shortcuts: http://en.wikipedia.org/wiki/File_shortcut

So I wanted to copy XREExeF and paste it as a shortcut and then add command line arguments to it.

Edit: Thanks to @nmaier I now know there is no cross-os method. Can you please show me os specific methods.


回答1:


No, there is no cross-platform way to create shortcuts. In fact there is not even a cross-browser format for shortcuts, as the Wikipedia page you already referenced tells you. Instead each platform uses it's own type(s) of links:

  • Windows: .lnk files and sometimes hardlinks and junctions.
  • *nix: (Symbolic) links (man 3 link, man symlink, `man ln)
  • Some *nix desktop environments: .desktop files.
  • Other *nix desktop environments: Whatever they want, if any.

Each of these things behaves differently. NTFS/*nix hard links are not even files, but just different names for the same file.

Also, the pinning you're describing is specific to Windows, anyway. Other desktop environments may use completely different pinning, if they even offer a comparable feature at all, or at least their pinning equivalents may have completely different semantics.




回答2:


Windows

In this example the shortcut created will be called "Mozilla Firef ya" and will open up a profile named "ya ya".

Cu.import('resource://gre/modules/FileUtils.jsm');
var exe = FileUtils.getFile('XREExeF', []);

var myShortcut = FileUtils.getFile('Desk', ['Mozilla Firef ya.lnk']);
var myShortcutWin = myShortcut.QueryInterface(Ci.nsILocalFileWin);

var myScIcon = new FileUtils.File('C:\\Users\\Noitidart\\Downloads\\amo-puzzle.ico'); //myScIcon must be converted to ico if it isnt an ico
myShortcutWin.setShortcut(exe, null, '-P "ya ya"', 'Launches Mozilla Firefox with "ya ya" Profile', myScIcon);
  • How to convert to ico:
    • https://gist.github.com/Noitidart/77006d9201d0e1dfe2be#comment-1291328 (based on https://stackoverflow.com/a/24270884/1828637) this main gist also has a processIcon function taken from MXR

*nix (Desktop) (FF doesnt work on non-desktop *nix's anyways i think)

https://stackoverflow.com/a/25516219/1828637

Mac

Use AppleScript here: https://ask.mozilla.org/question/1126/shortcut-created-on-mac-with-osfile-but-cant-get-around-unidentified-developer-error/



来源:https://stackoverflow.com/questions/24375166/copy-xreexef-and-paste-as-file-shortcut

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!