How do I copy the whole history of the clipboard to a text file?
Andrew Henderson
I would like to paste my whole clipboard history consisting of words copied (Ctrl+C/by selection) during my reading sessions. I installed programs like Glippy and ClipIt but I couldn't figure out how to paste all the words, if ever exists such an option in these programs, I copy to a simple text file at once, not one word at a time. Can someone help me out?
Thank you!
16 Answers
You can see some strings in clipit history file with this command:
strings ~/.local/share/clipit/historyBut it's not the best way. The output may be garbled.
there is python script for ClipIt
run it like this python cliphist.py > clipit.history.txt
#!/usr/bin/env python
"""cliphist.py: utility to print clipit history file.
If an argument is passed on the command line, it will
be used as a separator, otherwise history items are
separated by a blank line. """
import struct, os, sys
homedir = os.environ['HOME']
histfile = homedir + '/.local/share/clipit/history'
if len(sys.argv) > 1: sep = sys.argv[1]
else: sep = '---------------------------------------------------------------------'
with open(histfile,'rb') as f: f.read(68) size,_ = struct.unpack('2i',f.read(8)) while (size > 0): item = f.read(size) print item _,_,_,size,_ = struct.unpack('5i',f.read(20)) if size > 0: print sep 1 The latest version of Parcellite has a Save As menu item when clicking the icon. This will save all the history entries to a file. There is also a paste all when right-clicking the history list, which will place the entire history list on the clipboard. The preferences have a Paste All delimiter that it will put at the end of each entry.
ppa here:
Install KDE's Klipper Clipboard Manager and use the following simple script:
text="nothing yet"
cnt=0
while [ "$text" != "" ]; do text=`qdbus org.kde.klipper /klipper getClipboardHistoryItem $cnt` echo "==== Clipboard content line $cnt:" echo "$text" # to terminal output echo "$text" > /path/to/file # to file (EDIT this) cnt=$((cnt + 1))
doneNote: This does not behave very well in Unity so it seems. So in other desktop environments than KDE: your mileage may vary.
1Modified code from @stepan-shamaiev for Python 3 and without setting of separator:
#!/usr/bin/env python3
"""cliphist.py: utility to print clipit history file."""
import struct, os
homedir = os.environ['HOME']
histfile = homedir + '/.local/share/clipit/history'
with open(histfile,'rb') as f: f.read(68) size, _ = struct.unpack('2i', f.read(8)) while size > 0: item = f.read(size) print(item.decode()) _,_,_,size,_ = struct.unpack('5i',f.read(20)) if size > 0: print('------------------') user Parcellite, left click on its icon, "clear", select how many times you want, after that, "edit clipboard" and copy it all! Remember so set preference: use primary selection, to make it easier to copy the text!
2