如何使用 shell 脚本确定窗口是否实际显示在屏幕上?

如何使用 shell 脚本确定窗口是否实际显示在屏幕上?

我正在尝试编写一个 shell 脚本,识别 Thunderbird 窗口是否显示,如果显示,则将其处理到消息托盘中。

我想用它答案是“如何保持 Thunderbird 和 Pidgin 在后台运行?“ 问题。

到目前为止,我正在使用“xdotool”来检查 Thunderbird 是否显示,并且模拟关闭按照“如何通过脚本模拟按下“关闭”按钮?“。

    #!bin/bash
    thunderbird &
    TB=$(xdotool search --class thunderbird)
    while [ -z "$TB" ]; do
        sleep 2
        TB=$(xdotool search --class thunderbird)
    done
    xdotool search --class thunderbird windowunmap %@


但是xdotool search --class thunderbird在 Thunderbird 启动时返回结果,在实际显示之前,所以xdotool search --class thunderbird windowunmap %@等待永远不做任何事情。

为了绕过这个限制,在实际命令中添加了一个,但所需的睡眠时间因系统而异。sleep xx

我也使用过“xwininfo”来检查 Thunderbird 是否显示,但它的行为与“xdotool”相同,所以我必须在这里添加。sleep xx

    #!bin/bash
    thunderbird &
    t="Thunderbird"
    stop=0

    xwininfo -name $t > /dev/null 2>&1
    if [ $? -eq 0 ]; then
        stop=1
    fi

    while [ $stop -eq 0 ]; do
        xwininfo -name $t > /dev/null 2>&1
        if [ $? -eq 0 ]; then
            stop=1
        fi
    done
    sleep 2
    xdotool search --class thunderbird windowunmap %@

还有其他方法可以检查“真正”显示的窗口吗?

答案1

尝试这个:

wmctrl -l | grep -i thunderbird

相关内容