The command to get a fixed string into the clipboard is very easy, it's simply
xsel -ib <<< 'Your string goes here'
or if you want to read the string from a file
xsel -ib < your-file.txt
or from a command output
your-command | xsel -ib
Directly writing a fixed string by emulating keypresses is not much more complex though
xvkbd -file - <<< 'Your string goes here'
or if you want to read the string from a file
xvkbd -file your-file.txt
or from a command output
your-command | xvkbd -file -
You can simply create a custom shortcut in the System Settings → Keyboard → Shortcuts configuration and assign a command to the key combination you wish.
But take care that the shortcut interpreter is not Bash or a similar shell, so our <<<
("here string" syntax) or |
pipes will not work. To solve this anyway, we simply enclose our shell command with bash -c "INSERT COMMAND HERE"
. Just pay attention that you don't use double quotes inside the command then.
Here are the commands how you would have to enter them into the shortcut settings:
Copy "my string" to clipboard:
bash -c "xsel -ib <<< 'my string'"
Copy content of my-file.txt
to clipboard:
bash -c "xsel -ib < my-file.txt"
Copy output of my-command
to clipboard:
bash -c "my-command | xsel -ib"
Directly paste/write "my string":
bash -c "xvkbd -file - <<< 'my string'"
Directly paste/write content of my-file.txt
:
bash -c "xvkbd -file my-file.txt"
Directly paste/write output of my-command
:
bash -c "my-command | xvkbd -file -"
Please note that neither xsel
nor xvkbd
are installed by default, so you probably need to install them first using this command:
sudo apt-get install xsel xvkbd
Best Answer
To paste a single string into a textfield
install both
xdotool
andxclip
:Add the following command to a shortcut key:
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.