Often I read a text and need to copy some text blocks to a separate file. Usually, I use copy/paste to some file like a.txt.
Is it possible I do only copy (CTRL+C) for the same effect writing to the file a.txt?
copy
Often I read a text and need to copy some text blocks to a separate file. Usually, I use copy/paste to some file like a.txt.
Is it possible I do only copy (CTRL+C) for the same effect writing to the file a.txt?
Best Answer
Here is a little Python 3 script that captures clipboard changes and prints them to the terminal:
You can save this file e.g. ...
~/bin/cliplog
(any name inside thebin/
directory in your user's home directory - you might have to create that directory and runsource .profile
first if it doesn't exist yet) if you want it for your user only,/usr/local/bin/cliplog
(any name inside/usr/local/bin/
- you needsudo
/ root privileges to save a file there though) if every user on your machine shall have access to it.Don't forget to make it executable using
chmod +x /path/to/wherever/you/saved/cliplog
.Now you can simply type the command
cliplog
(or however you named it) in your terminal and the script above will capture all changes to your clipboard and print the changed content.Please note that this command runs forever until you interrupt it by pressing Ctrl+C in the terminal. (Yes, it's the same shortcut for copying stuff on the desktop as for sending the SIGINT interrupt signal in the terminal.)
To automatically store this log in a file, simply use Bash's redirection:
Or if you want to both see the output and have it saved in a log file, use
tee
:If you want to append to the log file instead of overwriting it, use
>>
ortee -a
instead.