我的问题与Make wmctrl ignore other-than-current workspace's windows非常相似。
事实是我使用 XFCE 所以wmctrl实际上看到了更多的桌面。
petr@sova:~$ wmctrl -d
0 * DG: 1600x900 VP: 0,0 WA: 62,21 1538x879 1
1 - DG: 1600x900 VP: N/A WA: 62,21 1538x879 2
2 - DG: 1600x900 VP: N/A WA: 62,21 1538x879 3
3 - DG: 1600x900 VP: N/A WA: 62,21 1538x879 4
4 - DG: 1600x900 VP: N/A WA: 62,21 1538x879 5
5 - DG: 1600x900 VP: N/A WA: 62,21 1538x879 6
6 - DG: 1600x900 VP: N/A WA: 62,21 1538x879 7
7 - DG: 1600x900 VP: N/A WA: 62,21 1538x879 8
8 - DG: 1600x900 VP: N/A WA: 62,21 1538x879 9
Run Code Online (Sandbox Code Playgroud)
我有很多这样的快捷方式:
wmctrl -xa Chromium || chromium-browser
Run Code Online (Sandbox Code Playgroud)
如何wmctrl只搜索当前工作区?我愿意包装wmctrl自定义命令。
mre*_*req 10
好吧,我想出了我自己的脚本。至少我学会了一些 Ubuntu bash 脚本;)
#!/bin/bash
num=`wmctrl -d | grep '\*' | cut -d' ' -f 1`
name=`wmctrl -lx | grep $1 | grep " $num " | tail -1`
host=`hostname`
out=`echo ${name##*$host}`
if [[ -n "${out}" ]]
then
`wmctrl -a "$out"`
else
$2
fi
Run Code Online (Sandbox Code Playgroud)
它能做什么:
然后,根据结果:
用法(期望脚本名称为switch_to_app:
switch_to_app LookForThisString LaunchThisIfNotFound
Run Code Online (Sandbox Code Playgroud)
例如
switch_to_app Chromium chromium-browser
Run Code Online (Sandbox Code Playgroud)
编辑:更棒的版本 - 当您再次启动命令(例如再次按下按键)时,它会循环到窗口的另一个实例
#!/bin/bash
app_name=$1
workspace_number=`wmctrl -d | grep '\*' | cut -d' ' -f 1`
win_list=`wmctrl -lx | grep $app_name | grep " $workspace_number " | awk '{print $1}'`
active_win_id=`xprop -root | grep '^_NET_ACTIVE_W' | awk -F'# 0x' '{print $2}' | awk -F', ' '{print $1}'`
if [ "$active_win_id" == "0" ]; then
active_win_id=""
fi
# get next window to focus on, removing id active
switch_to=`echo $win_list | sed s/.*$active_win_id// | awk '{print $1}'`
# if the current window is the last in the list ... take the first one
if [ "$switch_to" == "" ];then
switch_to=`echo $win_list | awk '{print $1}'`
fi
if [[ -n "${switch_to}" ]]
then
(wmctrl -ia "$switch_to") &
else
if [[ -n "$2" ]]
then
($2) &
fi
fi
exit 0
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1930 次 |
| 最近记录: |