Search code examples
pythonlinuxshellx11autokey

Get and Set X11 clipboard(s) in Linux


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)?


Solution

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

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