Answers:
wmctrl命令似乎可以完成这项工作。它已经为我安装了,但是可以在存储库中使用,以防有人需要。
wmctrl -l 列出当前打开的窗口(包括gnome面板)。
wmctrl -a STRING将焦点对准标题中包含STRING的窗口。我不确定如果一个以上的窗口满足该条件会发生什么。
就我而言,命令是:
wmctrl -a Firefoxshell wmctrl -a something,其中某些内容在调试器终端标题中。
                    使用wmctrl与组合xdotool,你可以切换焦点到Firefox,然后执行键盘或鼠标操作。
在此示例中:
wmctrl -R firefox && \
  xdotool key --clearmodifiers ctrl+t ctrl+l && \
  xdotool type --delay=250 google && \
  xdotool key --clearmodifiers Tab Return
执行以下步骤:
我在ubuntu pc中使用以下脚本如何?用例就是这样。
   $ ./focus_win.sh 1            # focus on a application window that executed at first
   $ ./focus_win.sh 2            # second executed application window
在键盘自定义快捷方式中为其分配后,我正在使用它。ctrl + 1,ctrl + 2,...
猫focus_win.sh
#! /bin/sh
if [ "" = "$1" ] ; then
    echo "usage $0 <win index>"
    exit 1;
fi
WIN_ID=`wmctrl -l | cut -d ' ' -f1 | head -n $1 | tail -n 1`
if [ "" = "$WIN_ID" ] ; then
    echo "fail to get win id of index $1"
    exit 1;
fi
wmctrl -i -a $WIN_ID