如何将剪贴板的整个历史记录复制到文本文件中?

分享于 

1分钟阅读

ubuntu

  繁體

您可以使用以下命令看到一些字符串:


strings ~/.local/share/clipit/history



但这不是最好的方法,输出可能乱码。


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





文件  文本  TEX  cop  拷贝  历史  
相关文章