make ctrl+t open a new (chrome) tab when outside of chrome
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).
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.