Skip to content

Instantly share code, notes, and snippets.

@baojie
Last active January 3, 2016 03:39
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save baojie/8404108 to your computer and use it in GitHub Desktop.
Save baojie/8404108 to your computer and use it in GitHub Desktop.
monitor clipboard and save contents to a file
# 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