Format clipboard text from Docfetcher to xplorer2

I constantly use docfetcher, indexing documents (pdfs, excel, word, html, etc DocFetcher website)  and xplorer2 for viewing/storing results in scrap container (xplorer2 website). One thing that has been bugging me for a while is how when I copy a list of documents from DocFetcher I’ve had to copy and to excel before I could paste into xplorer2’s scrap container (just go here for explanation of scrap container http://zabkat.com/x2h_4.htm).  It appears that problem has to do with difference between Docfetcher (Java) and Windows line endings:
Docfetcher = ‘n’
Windows = ‘rn’
So, using pywin32’s clipboard module I’m just taking in the clipboard, replacing with windows ‘rn’ then putting it back to clipboard.

import win32clipboard

# get clipboard data
win32clipboard.OpenClipboard()
data = win32clipboard.GetClipboardData()

# Windows line endings are 'rn'
result = data.replace('n','rn')

# Empty clipboard
win32clipboard.EmptyClipboard()

# set clipboard to windows formated text
win32clipboard.SetClipboardText( result, win32clipboard.CF_TEXT )
win32clipboard.CloseClipboard()

Leave a Reply

Your email address will not be published. Required fields are marked *