假设我想在一个工作区中运行
sleep 10 && zenity --warning --text 'Wake up!'然后我在一个不同的工作空间里做其他的事情。如何使这个zenity窗口在我所在的任何工作区中弹出,而不是输入命令的原始工作区?还是让它在所有工作空间中弹出更容易呢?
发布于 2013-11-14 22:54:45
我还没有找到一种优雅的方法,可以让这样的对话同时出现在所有工作空间(多工),但经过一些修改后发现,wmctrl允许您设置一个窗口位置、大小(最重要的是)让它在当前的活动工作区中打开。
在我的具体案例中,我也需要它来处理通过cron和at调度的通知,这需要一种稍微不同的方法,如下面的shown脚本所示:
#!/usr/bin/env bash
## demo of how to raise a zenity-notification on the active workspace
## license: MIT copyright: antiplex
export DISPLAY=:0.0
## start wmctrl with a delay in subshell
(sleep 1; wmctrl -r TimedWarning -e 0,40,30,-1,-1; wmctrl -R TimedWarning) &
## launch a zenity dialogue of your choice
zenity --warning --title="TimedWarning" --text="Time is up!" --display=:0.0由于一些奇怪的原因,上面的脚本还会在使用at调度时,以及当终端仍然打开时,从终端窗口中将执行调度到活动工作区。
下面是另一个使用通知守护进程/ libnotify (在基于debian的系统上检查包libnotify-bin )的变体,它也不会在活动工作区上引发终端:
#!/usr/bin/env bash
## demo of how to raise a non-volatile libnotify-notification
## on the currently active workspace
## license: MIT copyright: antiplex
export DISPLAY=:0.0
## critical notifications with expire time 0 need to be manually confirmed
notify-send --expire-time 0 -u critical TimedWarning "Time is up!"
## rename window title as notify-send would name all its windows 'notify-send'
wmctrl -r notify-send -T TimedWarning
## set new position in upper left corner, keeping the windows size
wmctrl -r TimedWarning -e "0,40,30,-1,-1"
## raise window on currently active workspace
wmctrl -R TimedWarning 发布于 2014-12-07 17:31:35
我找到了一个更好的方法,基于反复印机的回答:
function alert {
# https://stackoverflow.com/questions/18880524/how-do-i-raise-window-to-all-workspaces-automatically-in-gnome2-metacity/19990162#19990162
export DISPLAY=:0.0
name="TimedWarning"
text="Time is up!"
function set-properties() {
while [ x"$(wmctrl -l | grep -i "$name")" = "x" ] ; do
sleep 0.001
done
wmctrl -r $name -b add,sticky,above
}
zenity --warning --title="$name" --text="$text" --display=:0.0 &
set-properties &
}https://stackoverflow.com/questions/18880524
复制相似问题