Accessing clipboard through software built on Python

Akkana Peck akkana at shallowsky.com
Sun Oct 28 15:08:22 EDT 2018


Tim Daneliuk writes:
> However, the highlighted text must be copied explicitly:
> 
> Highlight
> Ctl-C
[ ... ]
> X actually has several clipboard buffers and it can be tricky to get this going.  I don't recall,
> but either clipboard or pyperclip have a way to get to them all IIRC ...

To get the highlighted text in X without needing a copy, you want the
PRIMARY X selection rather than CLIPBOARD.

I think pyperclip can get it (it uses an external program like xsel,
and xsel can get any of the three X selections), or you can get the
selection using a GUI library like GTK, Qt or Tk. Some examples:
https://github.com/akkana/scripts/blob/master/pyclip

        ...Akkana



More information about the Python-list mailing list