我经常想知道如何使用xdotool实现libreoffice的自动化。我知道窗口必须从窗口堆栈中选择出来,我尝试将它作为一个窗口bash变量在bash脚本中的xdotool下编程。然后我试着发送下一个按键到窗口,但没有结果。现在,我想将ctrl+N命令传递给libre窗口,以打开一个新文档。
#!/bin/bash
/usr/bin/libreoffice
mywindow=$(xdotool search --class libreoffice)
xdotool windowactivate $mywindow && xdotool key --window $mywindow Next
xdotool key ctrl+n我确实得到了一个错误代码
There are no windows in the stack.
Invalid window '%1'
Usage: windowactivate [options] [window=%1]
--sync - only exit once window is active (is visible + active)
If no window is given, %1 is used. See WINDOW STACK in xdotool(1)发布于 2021-10-27 16:26:40
mywindow=$(xdotool search --class libreoffice-writer)。您可以通过命令wmctrl -lx看到打开窗口的类。它列出了由一个点分隔的更多的泛型类名和更具体的类。对于libreoffice,它是libreoffice.libreoffice-writer。xdotool search命令将检索某个类的所有窗口。因此,对于多个窗口,变量将包含由空格分隔的多个标识符,例如66167017 65540686。然而,windowactivate只支持一个参数。libreoffice命令后,进程将分叉到后台。还没有创建任何窗口。这就是为什么winactivate失败的原因。使用--sync选项让winactivate命令等待窗口的有效创建:mywindow=$(xdotool search --sync --class libreoffice.writer)发布于 2021-10-27 16:22:31
一个简单的解决方法是将LO放在后台,然后在xdotool命令之间添加延迟。
#!/bin/bash
/usr/bin/libreoffice &
sleep 10
mywindow=$(xdotool search --class libreoffice)
xdotool windowactivate $mywindow && xdotool key --window $mywindow Next
xdotool key ctrl+nhttps://askubuntu.com/questions/1371975
复制相似问题