There are lots of websites which only allow signing in with email address and password and I am tired of typing a long email address. I don't want my browser to remember my email. Can I assign a keyboard shortcut to print this email address so that every time I press the key I get my email address on current text field?
I am using Ubuntu 14.04 and I have very little knowledge about Ubuntu. I'm not talking about snippets. Just a defined text to paste when the key is pressed.
03 Answers
To paste a single string into a textfield
install both
xdotoolandxclip:sudo apt-get install xdotool xclipAdd the following command to a shortcut key:
/bin/bash -c "sleep 0.5 && printf '' | xclip -selection clipboard && xdotool key Control_L+v"Choose: System Settings > "Keyboard" > "Shortcuts" > "Custom Shortcuts". Click the "+" and add the command above to a key combination of your choice.
Now when enter the cursor in a textfield and choose your shortcut, it will type your email address.
7Tested on Ubuntu 20.04.
Similar to Jacob’s solution. Here, we will paste the text hello ♥ using the middle mouse click clipboard.
We won’t paste the text at the "| cursor" as using Ctrl+V but directly under the mouse cursor like when using the middle mouse click. You may replace xsel with xclip.
- Install
xdotoolandxsel:
sudo apt install xdotool xsel- Add the following command to a shortcut key:
/bin/bash -c 'echo -n "hello ♥" | xsel && xdotool click 2'Note: We use the clipboard of the middle mouse, so expect it to be erased along with the current selection when using your custom shortcut.
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 xselMy 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'