Getting text into the copy-paste buffer...

  • Thread starter David Hirschfield
  • Start date
D

David Hirschfield

Strange request, but is there any way to get text into the linux
copy-paste buffer from a python script ?

I know the standard python libraries won't have that functionality
(except as a side-effect, perhaps?), but is there a simple trick that
would do it on linux? A command line to get text into the buffer? Using
a gui toolkit as a proxy to get text in there?

I actually have a need for this, though it sounds bizarre,
thanks in advance,
-Dave
 
K

kdart

David said:
Strange request, but is there any way to get text into the linux
copy-paste buffer from a python script ?

I know the standard python libraries won't have that functionality
(except as a side-effect, perhaps?), but is there a simple trick that
would do it on linux? A command line to get text into the buffer? Using
a gui toolkit as a proxy to get text in there?

There's a utility called xclip that you can wrap with popen2 or
something similar. I use my own proctools:

import proctools
XCLIP = proctools.which("xclip")
es, arg = proctools.getstatusoutput("%s -o -selection primary" %
(XCLIP,))

"arg" has the X selection.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,763
Messages
2,569,563
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top