I'm trying to run xdotool type word
then xdotool key Return
from Startup Aplications Preferences.
But if I use &&
or ;
, xdotool evaluates it as continuation of input.
Ubuntu – Run several xdotool commands in one line separated from each other
command linexdotool
Best Answer
Long story short:
Use a script.
And put the path of the script in the
Exec
field.Long story:
According to the
xdotool
manpage:Command chaining via
;
or&
isn't possible, since that is shell syntax and Startup Applications doesn't support shell syntax. However, if all you wish to do is press Enter after typing something, there's a roundabout way to do so.When it says "ASCII" newline, it doesn't mean a bare
\n
. And command substitution (xdotool type "$(printf '\n')"
, say) eats trailing newlines. Following thisxdotools
forum post, I tried this:And it worked. But it only works if there is some character after the
\n
, and this obviously leaves a trailing space, which would not be what you want. I modified that to:And this works and leaves no trailing space. However, it might cause problems for those using Vi mode in their shell.
Thanks to @steeldriver's comments I figured out that this was due to me trying it out on the very terminal I was executing the commands on. Just a small gap between my pressing Enter and the
xdotool
command was enough for a single newline to be registered correctly. Thus:So either extending the line by quoting it:
or using the shell interpretation as @steeldriver suggested looks like the right option.
However, a script containing:
in the
Exec
field worked fine. Indeed, I always recommend using a script for complex commands in a desktop file.You can have a script with
/usr/bin/xdotool
in the shebang, but the manpage says "script
mode isn't fully fleshed out and may fall below your expectations", so I stuck to bash scripts.I might have been seeing things, but in my first couple of tries, I had to put a (small). That was an artifact of trying it out on the terminal that was executing the commands instead of another window.sleep
between thetype
andkey
commands