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