Cut and paste to X clipboard?

S

Stephen Boulet

Does anyone have a code sample for cutting and pasting to the X-clipboard in
python?

I'm actually using xorg-x11-6.7.0 under kde 3.2.3, so either the X clipboard
or the kde clipboard would work fine. Thanks.

--
Stephen

If your desktop gets out of control easily,
you probably have too much stuff on it that
doesn't need to be there.
Donna Smallin, "Unclutter Your Home"
 
S

Stephen Boulet

Stephen said:
Does anyone have a code sample for cutting and pasting to the X-clipboard
in python?

I found a solution for this thanks to the 'xsel' program:

Copy from the clipboard:

import os
s = popen('xsel').read()

Paste to the clipboard (ok this is a pia):

import os
filename = os.path.join(os.path.expanduser('~'),'.tempclipboard')
f = file(filename,'wb')
f.write(s)
f.close()
command = 'xsel < %s' % filename
os.popen(command).read()
os.remove(filename)

--

Stephen

If your desktop gets out of control easily,
you probably have too much stuff on it that
doesn't need to be there.
Donna Smallin, "Unclutter Your Home"
 
S

Sam Holden

I found a solution for this thanks to the 'xsel' program:

Copy from the clipboard:

import os
s = popen('xsel').read()

Paste to the clipboard (ok this is a pia):

import os
filename = os.path.join(os.path.expanduser('~'),'.tempclipboard')
f = file(filename,'wb')
f.write(s)
f.close()
command = 'xsel < %s' % filename
os.popen(command).read()
os.remove(filename)

What's wrong with:

import os
os.popen('xsel', 'wb').write(s)

?
 
S

Stephen Boulet

Sam said:
What's wrong with:

import os
os.popen('xsel', 'wb').write(s)

?

Nothing, other than I didn't know about it. ;)
Much better.

--

Stephen

If your desktop gets out of control easily,
you probably have too much stuff on it that
doesn't need to be there.
Donna Smallin, "Unclutter Your Home"
 

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,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top