Ich habe auf Bitte von Andreas das Script von ardiman etwas verändert. Wenn man den Firefox verwendet und mehrere Profile hat, öffnet sich nun der Profilemanager und man kann das Profil auswählen. Eine Batch-Datei wird nicht benötigt.
Bei mir und bei Andreas funktioniert das soweit.
Dennoch ein Hinweis. Ich habe nicht viel Zeit investiert. Den Code gibt's also ohne Gewähr und Wartung.
/* OpenURLWith.uc.js
* Open an application with the current page's URL.
* Script by ardiman, https://github.com/ardiman/userChrome.js/tree/master/openurlwith
*
* Changes applied by Casali (www.camp-firefox.de), 16.12.2017:
* - Made use of Components.classes["@mozilla.org/process/util;1"] instead of ["@mozilla.org/browser/shell-service;1"]
* hence args can be send to application/process
* - Added "-no-remote" start parameter for Firefox to lauch a second instance with different profile
* - Added some basic exception handling
*/
(function OpenURLWith() {
if (location != "chrome://browser/content/browser.xul") return;
const MENU_LABEL = "Öffnen mit ...";
const MENU_ACCESSKEY = "ö";
const FIREFOX_PATH = "C:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe";
const IE_PATH = "C:\\Program Files\\Internet Explorer\\iexplore.exe";
const OPERA_PATH = "C:\\Program Files (x86)\\Opera\\launcher.exe";
const CHROME_PATH = "C:\\Program Files (x86)\\PortableGoogleChrome\\Chrome\\chrome.exe";
var mMenus = [
{
label: "Firefox (Link)",
accesskey: "F",
application: FIREFOX_PATH,
get url() { return gContextMenu.linkURL; },
get shouldDisplay() { return gContextMenu.onLink; }
},
{
label: "IE (Link)",
accesskey: "I",
application: IE_PATH,
get url() { return gContextMenu.linkURL; },
get shouldDisplay() { return gContextMenu.onLink; }
},
{
label: "Opera (Link)",
accesskey: "O",
application: OPERA_PATH,
get url() { return gContextMenu.linkURL; },
get shouldDisplay() { return gContextMenu.onLink; }
},
{
label: "Chrome (Link)",
accesskey: "C",
application: CHROME_PATH,
get url() { return gContextMenu.linkURL; },
get shouldDisplay() { return gContextMenu.onLink; }
},
{
label: "-",
get shouldDisplay() { return gContextMenu.onLink; }
},
{
label: "Firefox (Seite)",
accesskey: "F",
application: FIREFOX_PATH,
get url() { return gBrowser.currentURI.spec; },
},
{
label: "IE (Seite)",
accesskey: "I",
application: IE_PATH,
get url() { return gBrowser.currentURI.spec; },
},
{
label: "Opera (Seite)",
accesskey: "O",
application: OPERA_PATH,
get url() { return gBrowser.currentURI.spec; },
},
{
label: "Chrome (Seite)",
accesskey: "C",
application: CHROME_PATH,
get url() { return gBrowser.currentURI.spec; },
},
{
label: "-",
get shouldDisplay() { return gContextMenu.inFrame; }
},
{
label: "Firefox",
accesskey: "F",
application: FIREFOX_PATH,
get url() { return document.commandDispatcher.focusedWindow.location.href; },
get shouldDisplay() { return gContextMenu.inFrame; }
},
{
label: "IE",
accesskey: "I",
application: IE_PATH,
get url() { return document.commandDispatcher.focusedWindow.location.href; },
get shouldDisplay() { return gContextMenu.inFrame; }
},
{
label: "Opera",
accesskey: "O",
application: OPERA_PATH,
get url() { return document.commandDispatcher.focusedWindow.location.href; },
get shouldDisplay() { return gContextMenu.inFrame; }
},
{
label: "Chrome",
accesskey: "C",
application: CHROME_PATH,
get url() { return document.commandDispatcher.focusedWindow.location.href; },
get shouldDisplay() { return gContextMenu.inFrame; }
}
];
init: {
let parentMenu = document.createElement("menu");
parentMenu.setAttribute("label", MENU_LABEL);
parentMenu.setAttribute("id", "ucjs_openurlwith-menu");
if (typeof MENU_ACCESSKEY != "undefined" && MENU_ACCESSKEY)
parentMenu.setAttribute("accesskey", MENU_ACCESSKEY);
document.getElementById("contentAreaContextMenu").insertBefore(
parentMenu, document.getElementById("context-sep-properties"));
let parentPopup = document.createElement("menupopup");
parentPopup.id = "ucjs_openurlwith-popup";
parentPopup.addEventListener("command", openApplication, false);
parentMenu.appendChild(parentPopup);
for (let i = 0, menu; menu = mMenus[i]; i++) {
let menuItem;
if (menu.label == "-") {
menuItem = document.createElement("menuseparator");
} else {
menuItem = document.createElement("menuitem");
menuItem.setAttribute("label", menu.label);
menuItem.setAttribute("id", "ucjs_openurlwith-"+menu.label.replace(/[()\s]/g,""));
if ("accesskey" in menu)
menuItem.setAttribute("accesskey", menu.accesskey);
menuItem.ouwMenu = menu;
}
parentPopup.appendChild(menuItem);
}
parentMenu.parentNode.addEventListener("popupshowing", setMenuDisplay, false);
}
function openApplication(aEvent) {
var menu = aEvent.target.ouwMenu;
var file = Components.classes["@mozilla.org/file/local;1"]
.createInstance(Components.interfaces.nsIFile);
file.initWithPath(menu.application);
// create nsIProcess
var proc = Components.classes["@mozilla.org/process/util;1"]
.createInstance(Components.interfaces.nsIProcess);
try {
proc.init(file);
}
catch(err) {
alert("Fehler beim Starten des Prozesses: " + err);
return;
}
// start process.
// in case firefox, use -no-remote start parameter
if (menu.application == FIREFOX_PATH) {
var args = ["-no-remote", gContextMenu.linkURL];
}
else {
var args = [gContextMenu.linkURL];
}
proc.run(false, args, args.length);
}
function setMenuDisplay() {
var menuItems = document.getElementById("ucjs_openurlwith-popup").childNodes;
for (var i = 0, menu; menu = mMenus[i]; i++)
menuItems[i].hidden = "shouldDisplay" in menu && !menu.shouldDisplay || menu.application=='';
}
})();
Alles anzeigen