Long story short:
Use a script.
# With some window selection magic, or a sleep
# if you want to do that manually.
xdotool type word
xdotool key Return
And put the path of the script in the
According to the
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'.
Command chaining via
& isn't possible. However, if all you wish to do is press enter after typing something, there's a roundabout way to do so.
Even though it says "ASCII" newline, it doesn't mean
\n. And my
xdotool had a nasty habit of eating trailing newlines. Following this
xdotools forum post, I tried this:
xdotool type "$(printf 'date\n ')"
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:
xdotool type "$(printf 'date\n\e ')"
And this works and leaves no trailing space. However, all this was in a terminal, with me typing the commands directly. This didn't work in a script. Worse, it is very difficult to get it working in a .desktop file, with the difficulties in escaping.
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:
sleep 0.1; xdotool type $'date\n'
But this didn't help the behaviour with the
printf command. In fact, the behaviour with
printf just got worse whether I tried with the same window or a different one. So either extending the line by quoting it:
xdotool type 'date
or using the shell interpretation as @steeldriver suggested looks like the right option.
However, a script containing:
xdotool type date
xdotool key Return
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 the