1

Is it possible to create a shortcut which allows me to copy a saved string everywhere I want?

For example let's say the saved string is "Hello" and every time that I press Ctrl+H it prints Hello whatever program which accepts text input I am using.

It doesn't have to necessary be a keyboard shortcut, it could be also a mouse shortcut with the right click.

More precisely I want a shortcut which allows me to copy a saved string on whatever web page I am so that I can use the shortcuts instead of typing the password everytime or memorizing it in the site.

  • I suspect my answer is not what you are looking for. If so, let me know and I'll remove it. – DK Bose Sep 6 '18 at 1:53
0

If you install xdotool using sudo apt install xdotool, you can use this small script and assign any convenient shortcut to it:

#! /usr/bin/env bash

bash -c 'sleep 0.5; xdotool getactivewindow type "HELLO"'

From man xdotool:

xdotool lets you programmatically (or manually) simulate keyboard input and mouse activity, move and resize windows, etc. It does this using X11's XTEST extension and other Xlib functions.

and getactivewindow makes xdotool carry out the requisite action on the the current active window.

Notes:

  • if you have powerful hardware, you can drop the sleep bit; if not, you may want to increase the sleep value
  • I haven't tested the script in Wayland where currently only a subset of xdotool commands works courtesy of XWayland.
  • how can i use this in order to print "HELLO" on other programs other than the terminal? for example if i wanted to print "HELLO" on sublimetext how should i edit this script? – Zeno Raiser Sep 6 '18 at 10:07
  • No, there's no need to edit the script. It will work in any window provided the window is active (= in focus); that's what getactivewindow does. But you have to install xdotool and its dependencies. Of course, for each string you want, you'll need a different script with a unique shortcut key. I'm not really sure what it is you want to do. If you edit your question to elaborate, that would be nice. – DK Bose Sep 6 '18 at 10:17
  • i didn't understand what should i do in order to have the saved string on the active window, when i launch the command bash -c 'sleep 0.5; xdotool getactivewindow type "HELLO"' it types the string only in the terminal – Zeno Raiser Sep 6 '18 at 11:35
  • 1
    You need to save both lines to a script, called hello.sh and assign a keyboard shortcut to it. Then, when you press the keyboard shortcut, HELLO will be typed in the window which is in focus. – DK Bose Sep 6 '18 at 13:09

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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