KDE clipboard on the command line

The attached python script clip.py makes it easy to use the KDE clipboard on the command line.

Basic usage

For the following examples it is assumed that the script is available in the search path as clip.

  • clip
    gives the content of the clipboard. You can use the switch -i 2 to obtain historic contents, here item number 2, of the clipboard (note that -i 0 refers to the current content).
  • clip "some text"
    Put "some text" into the clipboard.
  • ps | clip -
    Put the output of some program, here ps, into the clipboard.

Some examples

  • ssh $(clip)
    Connect to the server whose hostname is contained in the clipboard.
  • clip long_file_name
    Use the autocompletion of the shell to copy filenames conveniently to the clipboard.
  • cat todo | clip -
    Copy the content of files, here todo, to the clipboard.

KDE3 vs. KDE4

As TGarland pointed out in the comments, KDE4 uses dbus instead of dcop. The attached clip.py file works for KDE4. If you are still using KDE3 (from personal experience: KDE4 is a very worthy update) you can download clip3.py.

Attachment: 

Comments

KDE4 uses dbus instead of dcop. A similar script which utilizes dbus can be found here:

http://milianw.de/code-snippets/access-klipper-clipboard-on-cli-under-kde4

Thanks for the comment and the link! After a one line change of code the script now works for KDE4.

Thanks a million! This is exactly what I needed.

Post new comment

The content of this field is kept private and will not be shown publicly.