5

When I open gnome-terminal with multiple tabs from the command line, I would like to preselect (on the command line) which one of the tabs should get focus.

I tried

gnome-terminal --tab -t A --active --tab -t B

to set tab A as the active, but instead tab B becomes the active one.

1 Answer 1

6

Create the script bellow , make it executable with chmod +x scriptname, where script name is actual script name.

Run the script with 4 parameters. For example, I run it with activetab.sh TAB-1 TAB-2 TAB-3 TAB-4. You can call tabs anything you want, TAB-1 is just example.

You will be prompted for which tab you want to focus on, type it exactly as you've typed it in the argument

Note: you will need to have wmctrl and xdotool installed for this script to work ! sudo apt-get install wmctrl xdotool

The script

#!/bin/bash
# Author : Serg Kolo
# Date: April 11,2015
# Description: Open gnome-terminal with 4 tabs, and focus on tab with particular name
#
# set -x
echo "Which window to focus ? "
read FOCUS

gnome-terminal --tab -t $1  --tab -t $2  --tab -t  $3 --tab -t $4

if [ $? -eq 0 ]; then
    sleep 0.5
    WINID=$(xprop -root | awk '/_NET_ACTIVE_WINDOW/ && /0x/ {print $5}' | cut -d'x' -f2)


    while [ $(wmctrl -l | grep $WINID | awk '{print $4}') != $FOCUS ]; do
        xdotool key Ctrl+Page_Up
    done

fi

Demo

If you can't see animation bellow, open it in different browser (chromium or google chrome) , or follow this link : https://i.stack.imgur.com/2sWMb.gif

enter image description here

4
  • Like the answer ? Please upvote. Solved your problem ? Click the gray checkmark to accept the answer Apr 11, 2015 at 17:53
  • I'm impressed! Upvoted! ;-)
    – Fabby
    Apr 11, 2015 at 19:38
  • Great! I think I got this to work after some modifications.. :) Apr 12, 2015 at 17:51
  • Deleted my post and upvoted yours... Must've missed it a few years ago...
    – Fabby
    Apr 19, 2019 at 15:50

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .