在彼此分开的一行中运行多个 xdotool 命令

jan*_*not 11 command-line xdotool

我试图运行xdotool type word,然后xdotool key Return从启动Aplications首选项。
但是如果我使用&&or ;, xdotool 会将其评估为输入的延续。

mur*_*uru 16

长话短说:
使用脚本。

#! /bin/sh
# With some window selection magic, or a sleep 
# if you want to do that manually.
xdotool type word
xdotool key Return
Run Code Online (Sandbox Code Playgroud)

并将脚本的路径放在Exec字段中。


很长的故事:

根据手册xdotool

type
       Supports newlines and tabs (ASCII newline and tab). 
       With respect to "COMMAND CHAINING", this command consumes the
       remainder of the arguments and types them. That is, no commands can
       chain after 'type'.
Run Code Online (Sandbox Code Playgroud)

命令链通过;or&是不可能的,因为这是 shell 语法,而启动应用程序不支持 shell 语法。但是,如果您只想Enter在键入内容后按一下,那么有一种迂回的方法可以这样做。

当它说“ASCII”换行符时,它并不意味着一个裸的\n. 并且命令替换(xdotool type "$(printf '\n')"比如说)会吃掉尾随的换行符。在这个xdotools论坛帖子之后,我尝试了这个:

xdotool type "$(printf 'date\n ')"
Run Code Online (Sandbox Code Playgroud)

它奏效了。但它只有在 之后有一些字符时才有效\n,这显然会留下一个尾随空格,这不是你想要的。我将其修改为:

xdotool type "$(printf 'date\n\e ')"
Run Code Online (Sandbox Code Playgroud)

这有效并且不留下任何尾随空间。但是,这可能会给在 shell 中使用 Vi 模式的人带来问题。

感谢@steeldriver 的评论,我发现这是因为我在执行命令的终端上进行了尝试。我的按下Enterxdotool命令之间只有一个小间隙就足以正确注册单个换行符。因此:

sleep 0.1; xdotool type $'date\n'
Run Code Online (Sandbox Code Playgroud)

因此,要么通过引用来扩展该行:

xdotool type 'date
'
Run Code Online (Sandbox Code Playgroud)

或者使用@steeldriver 建议的 shell 解释看起来是正确的选择。

但是,脚本包含:

type
       Supports newlines and tabs (ASCII newline and tab). 
       With respect to "COMMAND CHAINING", this command consumes the
       remainder of the arguments and types them. That is, no commands can
       chain after 'type'.
Run Code Online (Sandbox Code Playgroud)

Exec现场工作得很好。事实上,我总是建议对桌面文件中的复杂命令使用脚本。

您可以/usr/bin/xdotool在 shebang 中使用脚本,但联机帮助页说“script模式未完全充实,可能低于您的期望”,因此我坚持使用 bash 脚本。

我可能已经看到了一些东西,但在我的前几次尝试中,我不得不sleeptypeandkey命令之间放一个(小)。那是在执行命令而不是另一个窗口的终端上尝试它的工件。