CmdUtils.injectJavascript() injects the Javascript into the content of the current tab - so it'll be run as though its from a web page, rather than in chrome like a Ubiquity command is. So it won't have the necessary privileges to interact with the browser.
However, you could import globalOverlay.js using mozIJSSubScriptLoader. Have a look at: http://developer.mozilla.org/en/mozIJSSubScriptLoader Assuming that works (I haven't tried it or seen it used by a Ubiquity command yet), I'll add a API to make it easier to use. As for why the method I used isn't working for you... I have no idea. Yes I'm using a newer development version of Ubiquity, but I'm pretty sure there are no differences that would affect that. - Blair On Wed, Oct 15, 2008 at 1:45 PM, Sunny <[EMAIL PROTECTED]> wrote: > > Blair: Any idea on using the *much* simpler solution of calling > goDoCommand(cmd)? I've also been unsuccessful at using the above code > in the 0.1.1. Are you using a newer development version? > > -Sunny > > On Oct 12, 11:06 pm, "Blair McBride" <[EMAIL PROTECTED]> wrote: >> Very odd. I just tested the following code, and it works for me: >> >> var aCommand = "cmd_copy"; >> var browserWindow = >> Components.classes["@mozilla.org/appshell/window-mediator;1"] >> .getService(Components.interfaces.nsIWindowMediator) >> .getMostRecentWindow("navigator:browser"); >> var controller = >> browserWindow.document.commandDispatcher.getControllerForCommand(aCommand); >> if(controller && controller.isCommandEnabled(aCommand)) { >> controller.doCommand(aCommand); >> >> } >> >> - Blair >> >> On Mon, Oct 13, 2008 at 10:13 AM, Sunny <[EMAIL PROTECTED]> wrote: >> >> > I have this sort of working, but not as I'd like. It seems that >> > getControllerForCommand always fails and I can't find a way to access >> > the goDoCommand (which is dumb). See below for my current >> > implementation that calls getControllers. Note that I must also pas a >> > null type of the getMostRecentWindow. I then iterate through all of >> > the controllers and doCommand for the first one that claims to support >> > it. There must be an easier and more effective way, but the >> > documentation for XUL is a mess for the novice and Ubiquity doesn't >> > seem to have the necessary built-in stuff from the >> > globalOverlay.js. >> >> > Any help would be greatly appreciated!!! >> >> > function doTheCommand(cmd) { >> > var wm = Components.classes["@mozilla.org/appshell/window-mediator; >> > 1"] >> > .getService(Components.interfaces.nsIWindowMediator); >> > var window = wm.getMostRecentWindow(null); >> > //var controller; >> > // >> > window.document.commandDispatcher.getControllerForCommand(cmd,controller); >> >> > var controllers=window.document.commandDispatcher.getControllers(); >> > for(i=0;i<controllers.getControllerCount();i++) { >> > var controller=controllers.getControllerAt(i); >> > if(controller.supportsCommand(cmd)) { >> > controller.doCommand(cmd); >> > displayMessage(cmd+"run"); >> > break; >> > } >> > } >> > } >> >> > function cmd_close() { >> > doTheCommand("cmd_close"); >> > } >> > function cmd_closeOtherTabs() { >> > doTheCommand("cmd_closeOtherTabs"); >> > } >> > function cmd_closeWindow() { >> > doTheCommand("cmd_closeWindow"); >> > } >> > function cmd_copy() { >> > doTheCommand("cmd_copy"); >> > } >> >> > ....etc.... > > > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "ubiquity-firefox" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/ubiquity-firefox?hl=en -~----------~----~----~----~------~----~------~--~---
