Cut and paste to X clipboard?

Stephen Boulet stephen.no at spam.theboulets.net.please
Tue Jun 29 01:39:54 EDT 2004


Stephen Boulet wrote:

> 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"



More information about the Python-list mailing list