I read the present topics on AskUbuntu, but none of them did fit exactly.
Situation is:
I want to replace the currently selected text (by calling a bash script via EasyStroke) with a modified version of this text. The text is modified by RegEx'es or so... it's part of the script, so it doesn't really matter.
Current state:
I can read the selection from the ClipBoard with xclip, modify it and copy it back to the ClipBoard with the following command (part of the called bash script):
xclip -o | sed 's/ab/ef/g' | xclip -sel clipThe test string is
cdabcdabcdabcdabAnd after applying the above command, the output (in the ClipBoard) is
cdefcdefcdefcdefwhich is correct. But the result is still stored in the ClipBoard and not pasted back to the application. I have to paste it to the currently running application with Ctrl+V manually.
Question is:
How can I automate the last step of pressing Ctrl+V to immediately paste the result to the application in which the source text has been selected?
I tried xclip and xsel, but I was unable to make them work the way described above.
Any suggestions?
11 Answer
Thanks to @meuh's comment above, I was able to complete this task:
Install these programs:
sudo apt-get -y install xclip xdotool libnotify-binCreate a
.bashscript for the transformation:#!/bin/bash # Script to replace selection with a 'sed' transformed output (callable with easystroke or similar) IN=`xclip -o` # Example: Replace all 'ab' by 'ef' RESULT=`echo "$IN" | sed -e 's/ab/ef/g` # Output result to clipboard xdotool type "$RESULT" # Transform result to HTML for output with notify-send RESULT_HTML=`echo "$RESULT" | sed 's/&/\&/g; s/</\</g; s/>/\>/g'` # Create a notification in the lower right corner with the transformation notify-send "Changed clipboard text" "Input: $IN\nOutput: $RESULT_HTML"Call this script from easystroke or a similar program that processes key- or mouse-strokes.