Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Select a tab in Firefox from command line

Firefox already lets you open new URLs from the command line. Is there a way to select an existing tab from the command line, by title or URL?

like image 357
Eleno Avatar asked Nov 01 '22 01:11

Eleno


1 Answers

Yes, there is:

  • install MozRepl addon
  • start it: Tools -> MozRepl -> Start
  • use telnet to connect to the running MozRepl instance:

    $ telnet 127.0.0.1 4242
    

    You can also use rlwrap to enable readline-like keybindings inside telnet session:

    $ rlwrap telnet 127.0.0.1 4242
    
  • define a function for searching a tab with a given URL and switching to it. This one from https://github.com/emacsmirror/cedet/blob/master/lisp/cedet/semantic/db-mozrepl.el is pretty cool:

    function semanticselecttab(url) {
         var numTabs=gBrowser.browsers.length;
         for(i=0; i<numTabs-1; i++) {
           if(gBrowser.browsers[i].contentDocument.location.href.indexOf(url)>=0) {
             gBrowser.tabContainer.selectedIndex=i;
             break;
           }
         }   
    }
    
  • run it like this:

    repl> semanticselecttab("https://stackoverflow.com/questions/31055148/select-a-tab-in-firefox-from-command-line")
    
like image 69
Arkadiusz Drabczyk Avatar answered Jan 04 '23 13:01

Arkadiusz Drabczyk