Question

I have Foxit Reader running in WINE on Ubuntu 12.04. I want to copy and paste text into a bookmark, but I need to capitalize it (e.g., fusion becomes Fusion). I want to press F5 and run a python script. I understand this is possible with Autokey, but the latter has a documented bug with its clipboard handling.

So, now I'm looking for clipboard alternatives for Autokey. If my python script runs a shell, perhaps the shell could access the clipboard? xclip seemed promising but its documentation says, "Reads from standard in, or from one or more files, and makes the data available as an X selection for pasting into X applications." I don't need standard in or a file; I need the proper X11 clipboard (aka selection).

In short, how can python or a shell read the existing X11 clipboard(s)?

Was it helpful?

Solution

xclip -o | sed 's/^./\U&/g' | xclip -i

This will read the X clipboard, capitalize the content and overwrite it

OTHER TIPS

I realized that the -o parameter reads a selection, but you must specify which you need:

xclip -selection clipboard -o

From there, I used this StackOverflow answer. It works nicely.

#read clipboard, avoid autokey's get_selection bug
tag = subprocess.Popen(["xclip","-selection", "clipboard", "-o"],stdout=subprocess.PIPE).communicate()[0]

#https://stackoverflow.com/questions/764360/a-list-of-string-replacements-in-python
mapping = { "'":'', ',':'', '"':'', ';':'', '(':'', ')':'', '.':'', '-':' '}
for k, v in mapping.iteritems():
    tag = tag.replace(k, v)

#Camelcase, remove spaces, and append Caesar tag
tag=tag.title().replace(' ','')+"_"
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top