Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Cut and paste to X clipboard?

Reply
Thread Tools

Cut and paste to X clipboard?

 
 
Stephen Boulet
Guest
Posts: n/a
 
      06-25-2004
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"
 
Reply With Quote
 
 
 
 
Stephen Boulet
Guest
Posts: n/a
 
      06-29-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('~'),'.tempclipboa rd')
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"
 
Reply With Quote
 
 
 
 
Sam Holden
Guest
Posts: n/a
 
      06-29-2004
On Tue, 29 Jun 2004 00:39:54 -0500,
Stephen Boulet <(E-Mail Removed)> wrote:
> 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('~'),'.tempclipboa rd')
> 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)

?


--
Sam Holden
 
Reply With Quote
 
Stephen Boulet
Guest
Posts: n/a
 
      06-29-2004
Sam Holden wrote:

> 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"
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
cut and paste james41@bellsouth.net Computer Support 1 04-08-2005 01:06 AM
custom cut copy and paste =?Utf-8?B?QW5nZWw=?= ASP .Net 0 01-10-2005 06:13 PM
Cut and paste images Esteban Java 5 09-15-2004 09:38 PM
Cut and paste cookies? Starstuffed Computer Support 0 10-14-2003 04:22 AM
removing "favorites" and how to "cut and paste" shirley Microsoft Certification 1 09-26-2003 10:27 PM



Advertisments