Last active
January 3, 2016 03:39
-
-
Save baojie/8404108 to your computer and use it in GitHub Desktop.
monitor clipboard and save contents to a file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# sudo apt-get install xclip | |
# sudo pip install xerox begin | |
import time | |
import sys | |
import os | |
import io | |
import xerox | |
import begin | |
END = ">>END<<" | |
@begin.start | |
def paste_book(name): | |
print "write to '{}', add clipboard '{}'' to terminate".format(name, END) | |
print "======= BEGIN =======" | |
f = io.open(name, 'a', encoding='utf8') | |
recent_value = u"" | |
while True: | |
tmp_value = xerox.paste() | |
if tmp_value == ">>END<<": | |
f.close() | |
print "======= END =======" | |
break; | |
if tmp_value != recent_value: | |
recent_value = tmp_value | |
print recent_value | |
f.write(recent_value) | |
f.write(u"\n\n") | |
f.flush() | |
time.sleep(0.1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment