从 shell 脚本最小化和提升窗口

Bus*_*ted 3 x11 window xdotool

我正在尝试运行一个脚本,该脚本将检查带有 gui 的 linux 机器上的互联网速度,关闭终端窗口,当查询完成时,窗口将给出答案。至于暂时——我可以把窗户放下,但不能打开。

    #!/bin/bash
    xdotool getactivewindow windowminimize
    #xdotool set_window --name speedy
    #xdotool set_window --icon-name speedy
    speedtest-cli --simple

    if [ $? -eq 0 ]
    then
    #xdotool windowactivate speedy
    xdotool windowfocus  #speedy
    xdotool key "F11"
    fi

    exec $SHELL
Run Code Online (Sandbox Code Playgroud)

Jig*_*aga 7

xdotool需要知道其所有操作的窗口 ID。您正确地用于getactivewindow获取windowminimize命令的窗口,但您还需要这样做以设置其名称。所以放

xdotool getactivewindow set_window --name speedy
Run Code Online (Sandbox Code Playgroud)

在最小化线之前。

然后您可以使用search它来查找它以便稍后激活。

xdotool search --name speedy windowactivate
Run Code Online (Sandbox Code Playgroud)

有关这一切如何工作的说明,请参阅手册页部分窗口堆栈命令链接

整个脚本:

#!/bin/bash
# rename the window for finding it again later
xdotool getactivewindow set_window --name speedy
xdotool search --name speedy windowminimize

speedtest-cli --simple

if [ $? -eq 0 ]
then
  xdotool search --name speedy windowactivate
  xdotool key "F11"
fi
Run Code Online (Sandbox Code Playgroud)