从 shell 脚本 Unity 判断窗口是否打开且未最小化

App*_*ple 5 command-line bash scripts unity

我想在我的 .bashrc 中添加一个小脚本,将终端背景设置为透明,如果我没有任何非最小化的非终端窗口打开,并且如果有打开的东西,则将终端背景保留为图像。

我在 Unity 中使用 12.04。

我设置终端背景没有问题,但我只能判断程序是否打开,无法判断窗口是否最小化。

我现在kludge:

if [ -z "$( ps -e | grep firefox )" ]
    then
        gconftool-2 --type string --set /apps/gnome-terminal/profiles/Default/background_type transparent
    else
        gconftool-2 --type string --set /apps/gnome-terminal/profiles/Default/background_type image
fi


(add inset for each of my most used programs)
Run Code Online (Sandbox Code Playgroud)

我很高兴能够在终端启动时进行判断,但是如果我可以在最小化(或关闭)最后一个打开的窗口时将终端变为透明,那将是惊人的。我猜是这样的:

export largewindows=  #number of open, non-minimised windows

if [ $largewindows -eq 0 ]
    then
        gconftool-2 --type string --set /apps/gnome-terminal/profiles/Default/background_type transparent
fi
Run Code Online (Sandbox Code Playgroud)

使用(以某种方式)一个小脚本,在打开、关闭、最小化或取消最小化程序窗口时运行它。

我不知道的:

  • 如何自动计算窗口(甚至正在运行的程序)的数量。

  • 每次打开/关闭/最小化/取消最小化窗口时如何运行脚本。

任何正确方向的建议将不胜感激 - 非常感谢!

Kai*_*Kai 1

要查找窗口,您可以使用xdotool搜索,例如

WID=`xdotool search "Mozilla Firefox" | head -1`
Run Code Online (Sandbox Code Playgroud)

xdotool 的行为看起来像您可以在第二部分中使用的东西,但不幸的是那里没有最大化和最小化事件 - 而且它仅适用于现有窗口 - 但您可以使用 cron 不时检查打开的窗口。