Linux clipboard tool?

Ovid on 2005-02-24T18:20:57

Does anyone know of a Linux utility that will let me redirect STDIN to the clipboard? I've been searching high and low and can't seem to find anything. Essentially, I'm looking for something like pbcopy.


On Windows...

jplindstrom on 2005-02-24T18:56:16

Not what you asked for, but others may be interested. On Windows, it looks like this (run pl2bat on it):
#!/usr/bin/perl -w
use strict;
use Win32::Clipboard;
 
Win32::Clipboard->Set( join("", <STDIN>) );
 
__END__

xclip

link on 2005-02-24T20:18:42

xclip http://people.debian.org/user/kims/xclip/ looks like it does what your looking for

Re:xclip

Ovid on 2005-02-24T20:43:04

Looks perfect, but it's a no-op on my system. It installed just fine, but even the example programs don't do anything :/

Re:xclip

samtregar on 2005-02-24T21:50:01

What kind of system are you on? It works fine on Fedora Core 3.

-sam

Re:xclip

Ovid on 2005-02-24T22:06:34

Fedora Core 2. I should upgrade on day, but I know so little about Linux internals that I'm scared to.

Re:xclip

link on 2005-02-24T21:58:53

No error message? Have you tried both reading and writing,maybe your apps are using different buffers to what xclip is expecting.

Re:xclip

hansel on 2005-02-25T07:23:07

I installed the debian package (from sarge) and the samples seemed to work well for me.

The debian maintainer added a note to the copyright file (http://packages.debian.org/changelogs/pool/main/x/xclip/xclip_0.08-4/xclip.copy right) that might interest you.

"Since Kim Saunders is the upstream author and was the Debian maintainer and was missing, I'm doing upstream type fixes in my own repository which can be seen at: http://svn.ev-en.org/viewsvn.php?project=xclip"

Regards,
-james.

some tcl/tk....

jmason on 2005-02-24T23:19:11

Cutting is hard, because you need an app that'll "own" the selection, and deal with paste requests.

Here's a short TCL/Tk script that does it, based on something similar I had for pasting. It's quite suboptimal, but should give the idea. Reimplementing in perl, and incorporating some smart forking and one-daemon-per-desktop code would be really nifty! ;)

#!/usr/bin/wish -f
# xcopy - set the current string selection to whatever's passed in on stdin

set text [read stdin]

# Set up the data handler ready for incoming requests
selection handle -selection PRIMARY . getData
# Now we grab the selection itself
selection own -command lost -selection PRIMARY .

proc getData {offset maxChars} {
  return [string range $::text $offset [expr {$offset+$maxChars}]]
}

proc lost {} {
  set text ""
  exit
}