5

Thank you for your support. I wish to make a bash script that uses the latest text copied and currently in clipboard.

0

3 Answers 3

4

There are keyboard shortcuts for GUI terminals , Ctrl+Shift+V and Shift+Insert already. A script and mouse are unnecessary here.

If you're specifically looking for commands, there are xclip and xsel. Both of them are used to manipulate clipboards ( of which there are two in Linux - primary and secondary, that's why two different keyboard shortcuts were mentioned in the beginning of this answer ). I am personally more of a xclip fan, and i regularly use echo text | xclip -sel clip to copy something to clipboard and xclip -out -sel clip to print out whatever is in my clipboard. This is especially useful when you want to filter out text or process text with another command like xclip -out -sel clip | grep 'some text that I am looking for'

NOTE: xclip and xsel don't come to Ubuntu by default. You must install them with sudo apt-get install PACKAGE_NAME command

If we want to go into TTY, there's no way to copy text there. You must either use something known as named pipe or just a plain text file.

3

You can leverage xdotool for simulating the keyboard and mouse.

So for pasting a text from clipboard we use Ctrl+Shift+v, you can simulate this in xdotool by:

xdotool key ctrl+shift+v

Also check of mouse actions, read man xdotool.


If not installed, install it by (available in the Universe repository):

sudo apt-get install xdotool
2
  • code(#! /bin/bash kdeconnect-send $(zenity --text="escriba la url a compartir" --entry --entry-text=$(xclip -o)))
    – Jesus
    Dec 5, 2016 at 3:53
  • I have used with good results: :code(#! /bin/bash kdeconnect-send $(zenity --text="escriba la url a compartir" --entry --entry-text=$(xclip -o))) a mini script for sharing url to kdeconnect. However the xdotool solution that you offered seems to work too. I really appreciate your help, but now i'd like to ask if you know some way to automatically copy chromium's current tab url. Thank you again.
    – Jesus
    Dec 5, 2016 at 4:00
3

I found a solution while i was surfing trhough this forum. i had to install "xclip"

sudo apt-get install xclip

then i use it in the terminal:

"$(xclip -o)"

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