我正在使用标准Mate桌面运行LMDE 2('Betsy'),并且具有以下脚本:
#!/bin/bash
# This script starts a specified terminal-binary in "Always on Top"-mode
# The assumption is, that 'wmctrl -l' sorts windows with the
# in such a way, that the more recently a window has been created,
# the lower it will be on the list ( compared to windows with the
# same title).
#
# This is my assumption based on a short observation. The window
# ids are probably given out in ascending hex numbers
#
# Note: Using the pid will not help, since all terminals seem to
# be having the same pid
term_title_def='Terminal'
term_title='Terminal_top'
term_cmd="mate-terminal --title=$term_title"
# start terminal, wait for window to appear and get id of most recently created window
# NOTE: a possible wrap-around of window ids has not been considered here!
eval $term_cmd
win_id=''
while [[ -z $win_id ]]; do
win_id=$(wmctrl -l | grep "[[:blank:]]$term_title\$" | tail -n 1 | awk '{ print $1 }')
done
# DEBUG
touch /tmp/$win_id
# rename, set as "Always on top"
wmctrl -ir $win_id -T "$term_title_def"
wmctrl -ir $win_id -b add,above
wmctrl -ia $win_id
不知何故,脚本ps aufx
在重启后首次从MATE-panel链接运行时,永远不会退出while循环(用进行检查)。后续调用按预期方式工作,即该链接完成了我想要的操作(请参阅上面的脚本注释)。
因此,我猜想在启动MATE之后立即以某种方式win_id
无法在while
-test中正确展开。或类似的东西。
这是为什么?
我现在将尝试类似的方法while true; do stuff; break; done
,希望它能起作用...
更新:用以下内容
替换while
上面的-loop
while true; do
win_id=$(wmctrl -l | grep "[[:blank:]]$term_title\$" | tail -n 1 | awk '{ print $1 }')
[[ $win_id ]] && break
done
没有改变任何东西。脚本仍然陷入无限循环...
我不知道这怎么工作。当你跑步
eval $term_cmd
您将打开一个终端窗口,脚本将不会执行任何其他操作,除非您将其关闭。您需要的是:
$term_cmd &
在后台运行它(不要使用eval
,它是不需要的)。然后,您也不需要选择wmctrl
输出的最后一行。,您正在设置终端标题,因此将其设置为唯一的grep
内容:
#!/bin/bash
# This script starts a specified terminal-binary in "Always on Top"-mode
# The assumption is, that 'wmctrl -l' sorts windows with the
# in such a way, that the more recently a window has been created,
# the lower it will be on the list ( compared to windows with the
# same title).
#
# This is my assumption based on a short observation. The window
# ids are probably given out in ascending hex numbers
#
# Note: Using the pid will not help, since all terminals seem to
# be having the same pid
term_title_def='Terminal'
term_title="Terminal_top_$$" ## Use the script's PID for a unique title
term_cmd="mate-terminal --title=$term_title"
## Start terminal. No need to wait, the loop will run until
## the terminal has been opened
$term_cmd &
win_id=''
while [[ -z "$win_id" ]]; do
## No need for '[[:blank:]]' and \$, you are using a unique title,
## keep the regex general.
win_id=$(wmctrl -l | grep "$term_title" | awk '{ print $1 }')
done
# DEBUG
touch /tmp/$win_id
# rename, set as "Always on top"
wmctrl -ir $win_id -T "$term_title_def"
wmctrl -ir $win_id -b add,above
wmctrl -ia $win_id
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句