awk Syndicate content

warning: Creating default object from empty value in /www/htdocs/w0065fc9/milianw/modules/taxonomy/taxonomy.pages.inc on line 33.

» Access klipper clipboard on CLI under KDE4

Wed, 08/13/2008 - 23:12

NOTE: find most recent version on github: https://github.com/milianw/shell-helpers/blob/master/clipboard

Here’s a little script you can save in your path and do things like

  1. # paste current clipboard into file
  2. clipboard > "some_file"
  3. # copy some file into clipboard
  4. cat "some_file" | clipboard

Actually I find it rather useful so I thought I should share it.

  1. #!/bin/bash
  2.  
  3. # Access your KDE 4 klipper on the command line
  4. # usage:
  5. # ./clipboard
  6. # will output current contents of klipper
  7. # echo "foobar" | ./clipboard
  8. # will put "foobar" into your clipboard/klipper
  9.  
  10. # check for stdin
  11. if ! tty -s && stdin=$(</dev/stdin) && [[ "$stdin" ]]; then
  12. # get the rest of stdin
  13. stdin=$stdin$'\n'$(cat)
  14. # oh, nice - user input! we set that as current
  15. # clipboard content
  16. qdbus org.kde.klipper /klipper setClipboardContents "$stdin"
  17. exit
  18. fi
  19.  
  20. # if we reach this point no user input was given and we
  21. # print out the current contents of the clipboard
  22. qdbus org.kde.klipper /klipper getClipboardContents

As usually, save the file (attached below) in your $PATH and make it executable.

PS: Thanks to Martin Vidner for his article on D-BUS btw. - it gave me the proper dbus commands. PPS: Thanks the the various comments below!