仅在启动 YouTube 时显示 Xfce4 面板

仅在启动 YouTube 时显示 Xfce4 面板

我的中间显示器底部有一个带时钟的面板。当我在 YouTube 上全屏观看时,当然看不到带时钟的面板。我想创建一个执行以下操作的脚本:

我想同时启动以下两个命令。启动 YouTube,并将右侧面板设置为显示时钟。

chromium-browser http://www.youtube.com
xfconf-query -c xfce4-panel -p /panels/panel-4/autohide-behavior -s 0

当我关闭 YouTube 标签或窗口时,此命令将运行。它会隐藏带有时钟的面板。

xfconf-query -c xfce4-panel -p /panels/panel-4/autohide-behavior -s 2

任何帮助我都非常感谢。谢谢。

答案1

以下脚本运行完美。:)

#!/bin/bash

# Check to see if Chromium is already running. 
# If it is not already running then it sleeps longer before recording the PID.
chrom_status=$(ps -e | grep chromium)

# Launch YouTube in Chromium
chromium-browser http://www.youtube.com &

# Display Xfce panel with clock
xfconf-query -c xfce4-panel -p /panels/panel-5/autohide-behavior -s 0

# Sleeping is essential here; otherwise the correct PID is not recorded.
# If you run the script and then immediately start opening up other Chromium windows and tabs, then the script will break.
if [ -z "$chrom_status" ]; then
    sleep 20
else
    sleep 5
fi

# Add YouTube PID to variable
ypid=$(ps -e | awk '/chromium/ { print $1 }' | tail -n1)

# Check every two seconds to make sure YouTube is still open
while true; do
    # Without sleep CPU usage is really high.
    sleep 2
    ypid_status=$(ps -e | grep "$ypid")
    if [ -z "$ypid_status" ]; then
        xfconf-query -c xfce4-panel -p /panels/panel-5/autohide-behavior -s 2
        exit 0
    fi
done

相关内容