10

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.

0

4 Answers 4

14

To paste a single string into a textfield

  1. install both xdotool and xclip:

    sudo apt-get install xdotool xclip
    
  2. Add the following command to a shortcut key:

    /bin/bash -c "sleep 0.5 && printf '[email protected]' | 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.

7
  • 1
    Out of interest, why is the sleep 0.5 necessary? I noticed that it does not work without this. Sep 21, 2016 at 9:35
  • 2
    @Exeleration-G If I remember well (it is a while ago) it is to make sure the shortcut keypress does not interfere with the simulated keypress by xdotool. Sep 21, 2016 at 10:17
  • 3
    xdotool type --clearmodifiers '[email protected]' Jan 23, 2018 at 13:26
  • @Jacob Vlijm I tried your method, but got disable for the shortcut no matter which key combinations I tried.
    – fixit7
    Jul 13, 2018 at 14:52
  • sleep duration can be customised. Lower will leave you less time to release your key combination but the text will come sooner.
    – Zatigem
    Feb 21, 2021 at 21:39
0

Tested 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.

  1. Install xdotool and xsel:
sudo apt install xdotool xsel
  1. 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.

0

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:

  1. echo -e "SIGNATURE" -- I'm using -e with echo here because my signature has a few \n in it
  2. xsel -b -- this basically tells the shell to copy the input (echo -e "SIGNATURE") to the clipboard
  3. seq 2 -- this exists in order to run the thing that's following it (xargs -I -- xdotool key ctrl+shift+v) twice* (see Observations)
  4. 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:

  1. Copies signature to the clipboard
  2. 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'
    
1
  • Please, improve the formatting. Nov 1, 2021 at 19:41
0

An alternative to xdotool key Control_L+v is:

$ echo "TEST String" | xclip -in -selection clipboard
$ xdotool type --delay 0 -- "$(xclip -out -selection clipboard)"

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .