Cut and paste to X clipboard?

Discussion in 'Python' started by Stephen Boulet, Jun 25, 2004.

  1. 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"
    Stephen Boulet, Jun 25, 2004
    #1
    1. Advertising

  2. 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"
    Stephen Boulet, Jun 29, 2004
    #2
    1. Advertising

  3. Stephen Boulet

    Sam Holden Guest

    On Tue, 29 Jun 2004 00:39:54 -0500,
    Stephen Boulet <> 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('~'),'.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)

    ?


    --
    Sam Holden
    Sam Holden, Jun 29, 2004
    #3
  4. 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"
    Stephen Boulet, Jun 29, 2004
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?QW5nZWw=?=

    custom cut copy and paste

    =?Utf-8?B?QW5nZWw=?=, Jan 10, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    361
    =?Utf-8?B?QW5nZWw=?=
    Jan 10, 2005
  2. tk
    Replies:
    0
    Views:
    839
  3. Esteban

    Cut and paste images

    Esteban, Sep 14, 2004, in forum: Java
    Replies:
    5
    Views:
    5,002
  4. Replies:
    4
    Views:
    256
    Randy Webb
    Dec 14, 2004
  5. Mahsha
    Replies:
    2
    Views:
    2,076
    Gregor Kofler
    Jun 4, 2009
Loading...

Share This Page