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.


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

# 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



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

enter image description here

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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