› Access klipper clipboard on CLI under KDE4 
Wed, 08/13/2008 - 23:12
Here’s a little script you can save in your path and do things like
# paste current clipboard into file clipboard > "some_file" # copy some file into clipboard cat "some_file" | clipboard
Actually I find it rather useful so I thought I will have to share it.
Since KDE4 D-BUS is used throughout KDE and thus in Klipper as well. IMO they should really rework the output of dbus-send or add some more flags (what about --quiet). Well that’s the reason why the script below is somewhat long. But nothing a little bit of bash+awk magic couldn’t cope with:
#!/bin/bash # check for stdin # since we don't want to wait endlessly we set a timeout # a pity `read` only supports seconds and no fractions... read -t 1 stdin if [[ "$stdin" != "" ]]; then # get the rest of stdin stdin=$stdin$(cat) # oh, nice - user input! we set that as current # clipboard content dbus-send --type=method_call --dest=org.kde.klipper \ /klipper org.kde.klipper.klipper.setClipboardContents \ string:"$stdin" exit fi # if we reach this point no user input was given and we # print out the current contents of the clipboard # note: I hate the output of dbus, dcop was much easier in that regard! dbus-send --print-reply --dest=org.kde.klipper /klipper \ org.kde.klipper.klipper.getClipboardContents | awk ' BEGIN { output = ""; } { if ( NR > 1 ) { output = output $0 "\n"; } } END { print substr(output, 12, length(output) - 13); }'
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.
| Attachment | Size |
|---|---|
| clipboard.sh | 946 bytes |
Comments
Here’s a little script you Thu, 11/20/2008 - 20:59 — Antonio (not verified)
Of course, it destroyed the “clipboard” file :-)
Greetings from Spain!
P.S. I suppose it’s
Thanks, fixed. Wed, 11/26/2008 - 18:42 — Milian Wolff
Thanks, fixed.
AWESOME! I was sick of Thu, 07/30/2009 - 02:31 — Sam Tresler (not verified)
AWESOME! I was sick of ctl-shift-V’ing 40 lines at a time so I googled and found this. Precisely what I was looking for, thank you.
Is there some way to access Tue, 08/11/2009 - 22:23 — Anonymous (not verified)
Is there some way to access the klipper history from the command line?
Just look for yourself: run Wed, 08/12/2009 - 01:09 — Milian Wolff
Just look for yourself:
*history*method you’d likeFor inspiration on how to use those stuff in bash see my script above.
I have just found the answer Wed, 08/12/2009 - 01:21 — Anonymous (not verified)
I have just found the answer to my question. The trick is not to use “dbus-send”. It works with qdbus org.kde.klipper /klipper getClipboardHistoryItem 0 qdbus org.kde.klipper /klipper getClipboardHistoryItem 1 qdbus org.kde.klipper /klipper getClipboardHistoryItem 2
Hi, interesting post really. Tue, 10/20/2009 - 14:58 — Joetke (not verified)
Hi, interesting post really. But I wonder whether KDE 4 is mandatory because when I run your script I got this response: Error org.freedesktop.DBus.Error.ServiceUnknown: The name org.kde.klipper was not provided by any .service files Regards.
Yes, this version is for KDE Thu, 10/22/2009 - 00:44 — Milian Wolff
Yes, this version is for KDE 4. I once had a KDE 3 version, but it looks like I lost it. It was much easier though, you’ll just have to exchange the DBUS stuff with the good old DCOP from KDE 3.
Thanks, it works flawlessly. Thu, 11/05/2009 - 14:38 — joetke (not verified)
Thanks, it works flawlessly. Regards from Strasbourg, France.
Post new comment