使用xdotool的脚本在重新启动时无法正常工作

我想运行streamus (chrome应用程序)从终端流式传输youtube并在同一个SE中询问与此相关的问题。 我也有一个很好的答案和我的问题的脚本。 但是那个脚本有一个小问题。 这是有助于从终端运行和播放streamus的脚本。

#!/bin/bash # Start Streamu /usr/bin/chromium-browser --disable-gpu --enable-offline-auto-reload --enable-offline-auto-reload-visible-only --app=chrome-extension://jbnkffmindojffecdhbbmekbmkkfpmjd/foreground.html & sleep 3 ACT=$(xdotool getactivewindow getwindowname) WID=$(xdotool search --limit 1 --name "^Streamus$") # Refresh the page xdotool windowactivate --sync "$WID" key ctrl+r # Wait three seconds to update the page (Ctrl+R). sleep 3 # "Press" Play xdotool windowactivate --sync "$WID" key alt+z echo "windowid: $WID active window: $ACT" 

因为我认为问题是由标题引起的,所以我添加了这个echo "windowid: $WID active window: $ACT"代码来监视脚本中发生的事情。

当我们重新启动并登录系统并执行上述脚本而不打开streamus应用程序时 。 它将打开streamus应用程序,但不会播放它。 这是结果

 X Error of failed request: BadWindow (invalid Window parameter) Major opcode of failed request: 3 (X_GetWindowAttributes) Resource id in failed request: 0x0 Serial number of failed request: 22 Current serial number in output stream: 23 X Error of failed request: BadWindow (invalid Window parameter) Major opcode of failed request: 3 (X_GetWindowAttributes) Resource id in failed request: 0x0 Serial number of failed request: 22 Current serial number in output stream: 23 windowid: active window: Miko@Miko-Notebook-PC: ~/Abraca 

这就是streamus应用程序的外观 在此处输入图像描述

但当我关闭该窗口并再次执行脚本时,我可以打开并播放streamus应用程序。

 windowid: 82781573 active window: Streamus 

如何在没有这些错误的情况下执行脚本?

Alt + Z是我在streamus中播放命令的自定义快捷方式