7

On Chrome OS it is always possible to open a new tab (or actually browser window) with the Ctrl+T keyboard shortcut. Is it possible to do this in Ubuntu?

Simply setting a keyboard shortcut won't work, because this will change the behaviour when inside Chrome (E.g. it will always open a new window instead of a new tab).

5
  • 1
    Is it fine if you need to create a separate file and install some new applications and forgo the Ctrl + t shortcut for other applications(like firefox) to accomplish this?
    – jobin
    May 5, 2014 at 18:26
  • With firefox you can make a custom shortcut key with: firefox -new-tab www.google.nl ! I don't have chrome sorry.
    – Kai
    May 5, 2014 at 23:05
  • Yep, @Kai's solution also works with chrome. Set the shortcut to execute google-chrome www.google.com and it should open a new tab instead of a new window. Unfortunately this doesn't work for the new tab page (about:home or chrome://newtab). Starting chrome with these URIs will always open a new window for some odd reason. One last note: I'd advise against reassigning CTRL+t on a system level because - just as Jobin said - it's used by a lot of different applications (e.g. Nautilus). May 7, 2014 at 14:45
  • Try "Ctrl + N" That will open a new windows. And "Ctrl + T" Will open a new tab inside of the active window.
    – MathCubes
    May 7, 2014 at 18:37
  • Could you please review my edits and also review the editing help to improve the readability of your questions in the future... ;-)
    – Fabby
    Oct 2, 2015 at 21:05

1 Answer 1

9
+50

Warning: The solution posted here will work to satisfy the issue posted, however, will render the Ctrl+t shortcutl useless for applications such as firefox, nautilus which use it to open tabs, similar to google-chrome even if no google-chrome windows are open.

The key here is to capture the window ID of google chrome, if it is open. This can be done using wmctrl, grep and awk(or with other applications too). Once you get the window ID, you can send any desired keystroke using xdotool.

wmctrl and xdotool are not available on a default installation. You can install them from the software center or by typing the following on a terminal:

sudo apt-get install wmctrl xdotool

and then paste the following to a file(give it your favourite filename and remember the filename, if you want it to be hidden, start the filename with a ., I am using .google_chrome_system_tab_open as the filename):

windowid=$(wmctrl -l | grep "Google Chrome" | awk -F ' ' '{print $1}') && xdotool key --window $windowid ctrl+t

Then press Alt+F2 and type the following:

chmod +x /path/to/the/file

replacing /path/to/the/file with the location of the file where you pasted the above set of commands, which in my case is /home/jobin/.google_chrome_system_tab_open.

Now, go to System settings -> Keyboard -> Shortcuts -> Custom Shortcuts and click on the + to add a new shortcut.

Provide a name to the shortcut(I am using "Google Chrome System tab open") and the paste the following in the text box ahead of "Command: "

/path/to/the/file

And then you can set the desired keystroke for this command; Ctrl+t in your case.

If you use something like Ctrl+; as the shortcut, you could be preserving Ctrl+t as the shortcut for firefox and nautilus.

7
  • thanks, that is very helpful. If it means sacrificing the global shortcut, then I guess it might not be worth it. Perhaps I should specify how to do this ONLY when there are no active windows. May 8, 2014 at 10:40
  • @bquast: Would that be very helpful, though?
    – jobin
    May 8, 2014 at 15:13
  • 2
    Well, for me, assigning it to a key not used much, like F7 or whatever would work as well. ctrl-t is a bit to common in other apps. So this solution should be fine. May 9, 2014 at 10:39
  • 1
    @LennartRegebro Good point. Indeed, the original poster's own keyboard might have special dedicated application keys that could be reassigned to Jobin's clever script. Sometimes there is even a "www" key that already maps to starting a web browser window/tab (as was the case on my old Sony Vaio that had Ubuntu installed). These require stretching the fingers a bit more from the main typing area, but I think muscle memory would work after using them a few times.
    – user29020
    May 9, 2014 at 20:11
  • One quick question: Wouldn't the system intercept the virtual keypress sent to chrome (causing a loop and funny results)? May 11, 2014 at 23:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.