As none of suggestions that I found were able to achieve what I wanted, I had to do my own research into the subject. Posting my one-liner below in case if someone ever wants to achieve something similar. Tested on Ubuntu 20.04.1.
What I needed?
One-liner that would paste my signature to websites (sounds stupid, I know, but to my surprise there's still no decent way to achieve that with Google Chrome) when I press the set hotkey.
What was wrong with the one-liner from @zatiranyk?
While technically it does achieve what I want, for reason I still don't understand it's not pasting text when clicking the set hotkey.
Preprequisites
xdotool and xsel are still going to be required. You can install them like this:
sudo apt install xdotool xsel
My version of the one-liner
bash -c 'echo -e "SIGNATURE" | xsel -b && seq 2 | xargs -I -- xdotool key ctrl+shift+v'
If you bind it to, say, super+v, every time you press super+v it would paste the set text ("SIGNATURE").
Here's a short breakdown of its parts:
- echo -e "SIGNATURE" -- I'm using -e with echo here because my signature has a few \n in it
- xsel -b -- this basically tells the shell to copy the input (echo -e "SIGNATURE") to the clipboard
- seq 2 -- this exists in order to run the thing that's following it (xargs -I -- xdotool key ctrl+shift+v) twice* (see Observations)
- xdotool key ctrl+shift+v -- xdotool simulates keyboard input, and in this case it's ctrl+shift+v, which's the default hotkey for pasting content from the clipboard
In other words, what this one liner does is it:
- Copies signature to the clipboard
- Forces pressing ctrl+shift+v 2 times to paste the clipboard content
Observations
Why the part xdotool key ctrl+shift+v is executed twice? Similar to the one-liner of @zatiranyk, pressing ctrl+shift+v one time does not do the trick for some reason
For whatever reason similar one-liner with the primary selection instead of the clipboard works 3-4 times out of 10:
bash -c 'echo -e "SIGNATURE" | xsel && seq 2 | xargs -I -- xdotool click 2'
A bit more unga bunga version of the one-liner will work like a charm too:
bash -c 'echo -e "SIGNATURE" | xsel -b && xdotool key ctrl+shift+v && xdotool key ctrl+shift+v'