› 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
# 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 should share it.
#!/bin/bash # Access your KDE 4 klipper on the command line # usage: # ./clipboard # will output current contents of klipper # echo "foobar" | ./clipboard # will put "foobar" into your clipboard/klipper # check for stdin if ! tty -s && stdin=$(</dev/stdin) && [[ "$stdin" ]]; then # get the rest of stdin stdin=$stdin$'\n'$(cat) # oh, nice - user input! we set that as current # clipboard content qdbus org.kde.klipper /klipper setClipboardContents "$stdin" exit fi # if we reach this point no user input was given and we # print out the current contents of the clipboard 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!
| Attachment | Size |
|---|---|
| clipboard.sh | 647 bytes |
Comments
for most purposes, this is Tue, 04/30/2013 - 19:41 — wxl (not verified)
for most purposes, this is excellent! however, trying to post a 3843-line long
VBox.log,/usr/bin/qdbuscomplains the argument list is too long. i can’t off-hand conceive of an elegant way to solve this problem. anyone?Thank you so much! Wed, 02/20/2013 - 09:51 — Anonymous (not verified)
Thank you so much!
This was so helpful. Thank Mon, 12/24/2012 - 04:53 — Anonymous (not verified)
This was so helpful. Thank you. Makes it so easy to write the clipboard to a file through a keyboard shortcut. Configured another keyboard shortcut in klipper to edit the clipboard so now can make anotations if needed with one keystroke, then dump with another!
that’s great! thnx! Mon, 03/14/2011 - 12:05 — Anonymous (not verified)
that’s great! thnx!
You should use qdbus, this Thu, 01/06/2011 - 21:33 — Jice (not verified)
You should use qdbus, this simplifies a lot. Here is the version I’m using:
So you won’t regret dcop good ol’ time anymore ;-)
thanks, updated the script Fri, 03/18/2011 - 17:13 — Milian Wolff
thanks, updated the script now.
You should change the script Tue, 12/21/2010 - 12:52 — Kevin Brubeck Unhammer (not verified)
You should change the script to say “read -r -t 1 stdin”, that is, add the -r option so that read won’t treat \1 etc. as escapes.
It’s very annoying when working on one-liners in the shell, then deciding they should go into a file, and then finding that all the sed commands are messed up =P
try the updated version on Wed, 12/22/2010 - 16:31 — Milian Wolff
try the updated version on github: https://github.com/milianw/shell-helpers/blob/master/clipboard
This small wrapper script Fri, 11/19/2010 - 07:17 — notslad (not verified)
This small wrapper script will put the output of the command into a GUI msgbox.. in case you want to see the results of piping the clipboard contents through a command by running it via alt-f2..
Very old post but still a Wed, 09/29/2010 - 11:19 — Paolo (not verified)
Very old post but still a good idea.
Just a thing: to get rid of that 1 second wait, I changed the beginning of the script (lines 6,7,9).
This way, the script doesn’t even try to read from standard input if it’s connected to a terminal.
thanks, incorporated into my Sat, 11/20/2010 - 19:14 — Milian Wolff
thanks, incorporated into my git branch.
This is awesome. I extended Thu, 05/06/2010 - 10:09 — Morten Slott Hansen (not verified)
This is awesome. I extended this with
xmlcopyeditorand KDE4 hotkeys to have a quick way to get the clipboard content into an XML editor.I created a script called
xmlCopyEditor_readClipboard.shAnd attached it to a hotkey combination
meta + shift + xThis has made my life so much better - hope others can find this usefull!
EDIT: fixed formatting, regards - Milian
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.
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
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.
Thanks Milian this helped me Tue, 12/06/2011 - 09:32 — Simon (not verified)
Thanks Milian this helped me a lot!
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.
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.
Dunno if you’re still fixing Sun, 09/25/2011 - 15:26 — alexs77 (not verified)
Dunno if you’re still fixing stuff, but UUoC always makes my wanna cry… :/
You’re “storing” the output of the clipobard script with:
clipboard > file
You can also feed it from standard input without having to “misuse” cat:
clipboard < file
Cheers! And thanks for the script ;)
I agree that “clipboard < Sat, 08/04/2012 - 14:35 — Sys (not verified)
I agree that “clipboard < file” is more optimized than “cat file | clipboard”, although:
Remembering “cat file | clipboard” is better for newbies, as they later can execute, for example, “ls | clipboard”.
However, newbies remembering “clipboard < file” have problems trying later things like “clipboard < ls”, which does not work, they still would have to remember this structure: “ls | clipboard”.
I agree that “clipboard < Sat, 08/04/2012 - 14:30 — Sys (not verified)
I agree that “clipboard < file” is more optimized than “cat file | clipboard”, although:
Remembering “cat file | clipboard” is better for newbies, as they later can execute, for example, “ls | clipboard”.
However, newbies remembering “clipboard < file” have problems trying later things like “clipboard < ls”, which does not work, they still would have to remember this structure: “ls | clipboard”.
Post new comment