Results 1 to 10 of 10

Thread: How to access the Clipboard?

  1. #1
    Join Date
    Jul 2005
    Location
    Ireland
    Beans
    Hidden!

    [SOLVED] How to access the Clipboard?

    I have no idea how to do this;

    I want to code a program that does the following;

    When I copy a piece of text in an X windows application (eg firefox) I want my program to be able to take the text from the clipboard and put it into a text file.

    I can't do this because I don't know how to get at this 'piece of text' in the clipboard.

    Any help would be appreciated.
    Last edited by ADT; July 20th, 2007 at 12:47 PM. Reason: solved
    Computer Hardware: | Pentium III 863.81MHz | 512 MB RAM |

  2. #2
    Join Date
    May 2005
    Location
    Helsinki, Finland
    Beans
    Hidden!

    Re: How to access the Clipboard?

    In python you'd do this:
    Code:
    import os
    s = popen('xsel').read()
    More info on X clipboard should be here www.freedesktop.org/standards/clipboards.txt, but freedesktop.org has some server problems at the moment...

  3. #3
    Join Date
    Jul 2005
    Location
    Ireland
    Beans
    Hidden!

    Re: How to access the Clipboard?

    Thanks, I never tried python before but I'll give it a shot.
    Computer Hardware: | Pentium III 863.81MHz | 512 MB RAM |

  4. #4
    WW is offline Iced Blended Vanilla Crème Ubuntu
    Join Date
    Oct 2004
    Beans
    1,532

    Re: How to access the Clipboard?

    That should be
    Code:
    import os
    s = os.popen('xsel').read()
    Also xsel is not installed by default. You'll have to install it first, e.g.
    Code:
    sudo apt-get install xsel
    (or use Synaptic). You will have to enable the universe repository, if you haven't already.

  5. #5
    Join Date
    Oct 2009
    Beans
    1

    Re: How to access the Clipboard?

    xsel >> file.txt

    This will append the current selection to file.txt. One can even assign short cut (keyboard binding) to run this command. I use it all the time to same notes on things I read

  6. #6
    Join Date
    Nov 2008
    Location
    India
    Beans
    45
    Distro
    Ubuntu 16.04 Xenial Xerus

    Re: How to access the Clipboard?

    how to assign the shortcut key?
    Arun

  7. #7
    Join Date
    Nov 2010
    Beans
    54
    Distro
    Ubuntu 10.10 Maverick Meerkat

    Re: How to access the Clipboard?

    There are multiple ways to accomplish this. Running a Bash script is one way. Bash is the default shell program in Ubuntu. A shell interprets command line input.

    The Bash Reference Manual
    Advanced Bash-Scripting Guide
    Greg's Wiki Chet Ramey's Bash Page
    Bash Hackers Wiki
    List of Bash online-tutorials
    [Bash Hackers Wiki]

    With a Bash script, you can use the xclip command line utility to redirect clipboard data to a file. Xclip is in the Software Center.

    xclip -o -sel clip > filename

    If you want to automatically increment the filename, put the routine inside a loop.

    The script can also avoid overwriting files, or assign the name to a formula that will never create a duplicate filename, such as according to the date and time (e.g. filename2011-08-24-122308). You can assign this Bash script to a hotkey, icon, activate upon startup, start/stop under certain conditions, etc.

  8. #8
    hakermania's Avatar
    hakermania is offline Τώρα ξέρεις τι γράφω εδώ!
    Join Date
    Aug 2009
    Location
    Greece
    Beans
    1,705
    Distro
    Ubuntu Development Release

    Re: How to access the Clipboard?

    For anyone following:
    In c++ you can see qclipboard lib for info

  9. #9
    Join Date
    Jun 2010
    Location
    Kuwait
    Beans
    57
    Distro
    Ubuntu 13.10 Saucy Salamander

    Re: How to access the Clipboard?

    you can also try xclip.
    you can use `xclip -o` inside of a command as well

  10. #10
    Join Date
    Aug 2011
    Location
    47°9′S 126°43W
    Beans
    2,172
    Distro
    Ubuntu 16.04 Xenial Xerus

    Re: How to access the Clipboard?

    Just wondering, is there also a way to set the clipboard from a script?

    (I haven't ready any of the aforementioned docs yet).

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •