Ubuntu: Global keyboard shortcut for new browser tab


I'm coming from OS X and I was using QuickSilver and AppleScripts to create global shortcuts for common actions. One that I used a whole lot was to open a new tab in Chrome and focus the omnibox, allowing me to do web searches etc with the Chrome completion doing lots of useful work for me.

I would like a similar setup. I'm using compiz and unity so I already found that ccsm will let me set up keyboard shortcuts for commands, so all I need is a command that will focus on a new Chrome tab.

I already tried xdg-open about:blank which almost does what I want, but it leaves 'about:blank' in the URL bar and the cursor not selecting it, so I'd have to do ctrl-A as well then. There's also a Chrome url chrome://newtab but xdg-open opens that in Firefox .

So basically, any way to achieve this would be appreciated, be it via D-Bus, XDG or X11 event injection (but robustly).


Why is chrome://newtab opening with firefox? This is probably something you could change.

If I'm understanding you correctly than an even simpler solution would be to use something like synapse to launch urls - which is a lot like QuickSilver.

The idea would be to press ctrl+space and begin typing a url wherever you are. You can then press enter which will automatically open the page in chrome if it has been set as your default browser.

By the way, synapse is not only good for this specific scenario but is a great tool in general to install and can greatly increase your productivity once you get used to it.

If you are using Kubuntu (like I am), then you can do the exact same thing with KRunner


After digging through xdg-open (it uses the chrome url handlers to just run google-chrome with the url) and getting the front window with xprop, I came up with this command line (thanks for the xte tip @Seth):

/opt/google/chrome/google-chrome about:blank ;  count=20;  while [ $count -gt 0 ] \        && ! xprop -id $(xprop -root _NET_ACTIVE_WINDOW | awk '{print $NF}') WM_NAME \        | grep -q about:blank; do    let count--;    sleep 0.1;  done;  if [ $count -gt 0 ]; then    xte 'keydown Alt_L' 'keydown D' 'keyup Alt_L' 'keyup D';  fi  

Not the nicest way of doing it, but it works. Would be great if there was application scripting on Gnome like AppleScript does...

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Next Post »