Programmatically open a new tab within a gnome-terminal?

2

Within a gnome-terminal tab, I can invoke the "New Terminal in New Tab" command shift+ctrl+t and it will add a tab to the current gnome-terminal window.

How can this be done programmatically?

I've tried various solutions mentioned here without success.

For example, exec gnome-terminal --tab --tab replaces the current tab with a new window with two tabs. (By the way, 'man gnome-terminal' makes no mention whatsoever of the --tab option!)

--tab-with-profile=PROFILE does the same thing, assuming one can identify the PROFILE in use, which is apparently not an easy thing to do (also, if the only profile defined is 'Default', as displayed by Edit: Preferences: Profiles, tab-with-profile does not recognise 'Default'!).

Urhixidur

Posted 2016-06-09T13:04:11.857

Reputation: 121

Answers

0

I have found that the following opens a terminal in a new window:

gksu -u `whoami` gnome-terminal

I have not yet found a way to open a new tab, but this may be sufficient for your purposes.

AFH

Posted 2016-06-09T13:04:11.857

Reputation: 15 470

0

This should be simple with xdotool

Untested, but something like:

xdotool key --clearmodifiers ctrl+shift+t

Jonathan

Posted 2016-06-09T13:04:11.857

Reputation: 1 287

0

The simplest concept is to use a program to actually enter the keystrokes

The answer is found here:

https://stackoverflow.com/questions/1188959/open-a-new-tab-in-gnome-terminal-using-command-line

Excerpt:

(shebang)/bin/sh
WID=$(xprop -root | grep "_NET_ACTIVE_WINDOW(WINDOW)"| awk '{print $5}')
xdotool windowfocus $WID
xdotool key ctrl+shift+t
wmctrl -i -a $WID

This will auto determine the corresponding terminal and open the tab accordingly.

SDsolar

Posted 2016-06-09T13:04:11.857

Reputation: 1 206