Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import time
- from os import SEEK_END
- #not mine #
- import win32clipboard as w
- import win32con
- def getText():
- w.OpenClipboard()
- try:
- d=w.GetClipboardData(win32con.CF_TEXT)
- except TypeError:
- d = 'Specified clipboard format is not available!'
- w.CloseClipboard()
- return d
- def setText(aType,aString):
- w.OpenClipboard()
- w.EmptyClipboard()
- w.SetClipboardData(aType,aString)
- w.CloseClipboard()
- #end not mine#
- #----------------------------------------------------------------------
- def savePaste(pasteData):
- """saves the paste to a file, timestamped:
- FRI DEC 1 2012
- PASTE: clipboard data here"""
- file = loadFile()
- print 'paste saved', pasteData
- timeData = time.strftime('%a %b %d, %Y at %I:%Ms%S')
- #append time/date
- #combiData = timeData, '\nPASTE:', pasteData
- combiData = "###### {0} ######\n{1}\n".format(timeData, pasteData)
- file.write(combiData)
- pass
- #----------------------------------------------------------------------
- def loadFile():
- """loads a text file with raw paste data, if none found, is created"""
- try :
- f = open('paste data2.txt', 'r+')
- print 'found file'
- #should seek to the end of a file
- f.seek(0, SEEK_END)
- except IOError:
- print 'not found file'
- #create the file
- open('paste data2.txt', 'w')
- f = open('paste data1.txt', 'r+')
- #should seek to the end of a file
- #f.seek(-1)
- print 'properly made a file'
- #else:
- #print 'dunno what happened'
- #f = 'Invalid file error'
- #should seek to the end of a file
- #f.seek(-1)
- print 'about to return:', f
- return f
- quit = False
- print 'Starting'
- #create a file
- loadFile()
- #set oldPaste to current clipboard
- oldPaste = getText()
- while not quit:
- #grab current clipboard
- curPaste = getText()
- #if the current paste and old paste are different
- if not curPaste == oldPaste:
- if curPaste == 'quit':
- print 'caught "quit", so I"m quitting'
- quit = True
- break
- print 'Clipboard has changed!'
- #save curPaste to a file or whatever
- savePaste(curPaste)
- #update old paste so it doesn't get caught twice
- oldPaste = curPaste
- #wait x seconds
- time.sleep(0.1)
- print 'end of while loop'
Advertisement
Add Comment
Please, Sign In to add comment