2

I have to paste my email often during the day, and typing it is time consuming. That is why I am searching for a way to do this with a button press. The following command works to place my mail on my clipboard when used in bash:

echo "lorem@ipsum.com" | xclip -sel clip

And after running it I can successfully go to another application like Firefox and press ctrl+v to paste it. When I use this command with a shortcut it doesn't work however. example shortcut

Any Idea how to make this work?

P.S. I also tried 'xdotool' by setting a keyboard shortcut to:

xdotool type 'l' 'o' 'r' 'e' 'm' '@' 'i' 'p' 's' 'u' 'm' '.' 'c' 'o' 'm'

And some variations of that but all of them are too laggy and only start printing halfway through the string.

1

Think you might want to combine the two like this:

sh -c 'sleep 0.5; xdotool type "$(xclip -o -selection clipboard)"'

for just making a keybinding to selecting the text. You need to make sure that the meta-keys in the binding are not pressed when it tries to run the command (xdotool creates keypresses, and it won't release the Ctrl key for you).

Second, by default xclip selects XA_Primary buffer rather than the XA_CLIPBOARD. So you should pass clipboard as the selection parameter for xclip.

Or just:

sh -c 'sleep 0.5; xdotool type "lorem@ipsum.com"'

xclip alone:

sh -c 'echo "lorem@ipsum.com" | xclip -sel clip && xclip -out -sel clip'

But it's a long, overpiped command (personally I don't like that).

  • Thanks, the xdotool works now. Is there also an xclip only solution for if I just want to write something to clipboard? – RnRoger Jul 5 at 11:46
  • 1
    It even works with 0.1 seconds so the sleep workaround drawback is minimal. – RnRoger Jul 5 at 11:51
  • I believe sh -c 'echo "lorem@ipsum.com" | xclip -sel clip | xclip -out -selection clipboard' should work, though it's a long one... combination of xdotool and xclip or xdotool alone would be better, I think. – Bart Jul 5 at 11:52
  • 1
    It works perfectly, Bart! I agree that xdotools works well for my use case, plus I don't have to manually paste. But it is still great functionality that I will keep in mind for the future. – RnRoger Jul 5 at 11:59
  • @RnRoger, I've added minor change to the xclip command, since with the second pipe it was outputting previous clip anyway. with && operand, it outputs correct data. – Bart Jul 5 at 12:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.