Launching Multiple Tabs in Gnome Terminal

I desire that when I log into my gnome workstation that a gnome-terminal pops up, with several tabs already opened and commands already running in them.

I read the man page, and tried to accomplish this with a simple script:

gnome-terminal --tab -t htop -- htop 
gnome-terminal --tab -t XPRA -e 'xa' 
gnome-terminal --tab -t hosta -- autossh -M $RANDOM a
gnome-terminal --tab -t hostb -- autossh -M $RANDOM b
gnome-terminal --tab -t hostc -- autossh -M $RANDOM c
gnome-terminal --tab -t MTR  -- mtr

I ran that script and up popped all the tabs I wanted. Neat. So then I put it in an autostart file:

$ cat .config/autostart/StartTerms.desktop 
[Desktop Entry]
Comment=Start my terminal sessions (autossh to various servers)

Raise your hand if you know what I was doing wrong…

I rebooted, logged in, and boom, I get pummeled with 6 individual windows, NOT 6 tabs in one window.

I thought: "Perhaps the second and subsequent gnome-temrminal --tab commans are being invoked before the first one has caused its window to display, so the subsequent ones think they’re all first and open their own windows.

I also found out that if autossh runs before the wifi is connected, then it exits.

So I found out that wmctrl can list all the visible windows. I figured that during the time between the gnome-terminal command being invoked and the time it’s ready to accept new --tabs from another command, its window would’t be in that list, so put this clever bit together right after the first one runs and before any subsequent invocations:

touch "${lock}"
while [[ -f "${lock}" ]] 
	wmctrl -lp | \
	while read hex zero pid foo
		if grep -q 'gnome-terminal-server' '/proc/'"${pid}"'/cmdline'
			echo "Process ${pid} is an already-visible terminal.  save to proceed..."
			rm "${lock}"
			break 2
	if [[ -f "${lock}" ]]
		sleep 1

AAAAAND fail. IT still bombs me with multiple seperate windows on login. What on earth am I doing wrong? How can I get multiple taps to come up with specific commands in them when I log into gnome?

When I run that script from Files, with no existing terminal window open, it pops open multiple terminal windows. It works correctly only when I run the script from a terminal.

I think all you need to do to make the above script work is to change your .desktop file, and replace the Exec line with this:

Exec=gnome-terminal -- /home/myuser/bin/StartTerms

For me that opens a terminal with multiple tabs.

This topic was automatically closed 45 days after the last reply. New replies are no longer allowed.