# Clipboard command line utility

**URL:** <https://www.ruby-forum.com/t/clipboard-command-line-utility/124823>\
**Category:** Ruby\
**Created:** [January 2, 2008, 10:10pm UTC](https://www.ruby-forum.com/t/clipboard-command-line-utility/124823 "2008-01-02T22:10:49Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![dfinnie](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/e9bcb4/32.png) [@dfinnie](https://www.ruby-forum.com/u/dfinnie)\
**Post date:** [January 2, 2008, 10:10pm UTC](https://www.ruby-forum.com/t/clipboard-command-line-utility/124823/1 "2008-01-02T22:10:49Z")

</div>

I’ve been doing a lot of Python for Google’s Highly Open Participation  
contest lately but finally found the time to make a utility I thought  
of a few weeks ago. Basically, it allows you to pipe to and from the  
clipboard on the command line. Example:

daniel@daniel-desktop:~$ echo ‘ruby’ | clipboard  
daniel@daniel-desktop:~$ clipboard  
ruby  
daniel@daniel-desktop:~$

You can also access it with the normal Control-C/Control-V shortcuts.

So, it’s a great concept, but not such a good implementation. First,  
I doctored the output above. ruby-gnome2 seems to be outputting error  
messages that I can’t get rid of, even after a Google search. This is  
the real output:

daniel@daniel-desktop:~$ echo ‘ruby’ | clipboard  
/usr/lib/ruby/1.8/glib2.rb: line 55  
GLib-GObject-CRITICAL \*\*:g\_boxed\_type\_register\_static: assertion  
`g_type_from_name (name) == 0' failed /usr/lib/ruby/1.8/glib2.rb: line 55 GLib-GObject-CRITICAL **:g_param_spec_boxed: assertion `G\_TYPE\_IS\_BOXED (boxed\_type)’ failed  
/usr/lib/ruby/1.8/glib2.rb: line 55  
GLib-GObject-CRITICAL \*\*:g\_object\_class\_install\_property: assertion  
`G_IS_PARAM_SPEC (pspec)' failed /usr/lib/ruby/1.8/glib2.rb: line 55 GLib-GObject-CRITICAL **:g_param_spec_boxed: assertion `G\_TYPE\_IS\_BOXED (boxed\_type)’ failed  
/usr/lib/ruby/1.8/glib2.rb: line 55  
GLib-GObject-CRITICAL \*\*:g\_object\_class\_install\_property: assertion  
`G_IS_PARAM_SPEC (pspec)' failed daniel@daniel-desktop:~$ clipboard /usr/lib/ruby/1.8/glib2.rb: line 55 GLib-GObject-CRITICAL **:g_boxed_type_register_static: assertion `g\_type\_from\_name (name) == 0’ failed  
/usr/lib/ruby/1.8/glib2.rb: line 55  
GLib-GObject-CRITICAL \*\*:g\_param\_spec\_boxed: assertion  
`G_TYPE_IS_BOXED (boxed_type)' failed /usr/lib/ruby/1.8/glib2.rb: line 55 GLib-GObject-CRITICAL **:g_object_class_install_property: assertion `G\_IS\_PARAM\_SPEC (pspec)’ failed  
/usr/lib/ruby/1.8/glib2.rb: line 55  
GLib-GObject-CRITICAL \*\*:g\_param\_spec\_boxed: assertion  
`G_TYPE_IS_BOXED (boxed_type)' failed /usr/lib/ruby/1.8/glib2.rb: line 55 GLib-GObject-CRITICAL **:g_object_class_install_property: assertion `G\_IS\_PARAM\_SPEC (pspec)’ failed  
ruby  
daniel@daniel-desktop:~$

I have tried doing something like this with stderr, stdout, and defout  
with no luck:  
require ‘stringio’

old\_stderr = $stderr  
$stderr = StringIO.new

require ‘gtk2’

$stderr = old\_stderr

Any suggestions?

I have posted the full source code to [http://ruby.pastebin.com/f5ef5f028](http://ruby.pastebin.com/f5ef5f028)

I would also like a better way to capture STDIN without blocking if  
there is no text on STDIN.

Thanks,  
Dan Finnie  
removed\_email\_address@domain.invalid

---

<div class="post-metadata">

**Author:** ![dfinnie](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/e9bcb4/32.png) [@dfinnie](https://www.ruby-forum.com/u/dfinnie)\
**Post date:** [January 2, 2008, 10:32pm UTC](https://www.ruby-forum.com/t/clipboard-command-line-utility/124823/2 "2008-01-02T22:32:29Z")

</div>

On Jan 3, 2008 2:39 AM, dfinnie [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> You can also access it with the normal Control-C/Control-V shortcuts.  
> /usr/lib/ruby/1.8/glib2.rb: line 55  
> `G_IS_PARAM_SPEC (pspec)' failed /usr/lib/ruby/1.8/glib2.rb: line 55 GLib-GObject-CRITICAL **:g_param_spec_boxed: assertion `G\_TYPE\_IS\_BOXED (boxed\_type)’ failed  
> /usr/lib/ruby/1.8/glib2.rb: line 55  
> GLib-GObject-CRITICAL \*\*:g\_object\_class\_install\_property: assertion  
> `G\_IS\_PARAM\_SPEC (pspec)’ failed  
> ruby  
> daniel@daniel-desktop:~$

I have seen these errors as well, you will have better luck if you  
compile ruby-gnome2 directly from SVN.  
Yeah, it has lots of dependencies, but probably you will have them.

I will love to play with code and see where it takes me!

> $stderr = old\_stderr  
> removed\_email\_address@domain.invalid

–  
Let them talk of their oriental summer climes of everlasting  
conservatories; give me the privilege of making my own summer with my  
own coals.

[http://gnufied.org](http://gnufied.org)

---

<div class="post-metadata">

**Author:** ![dfinnie](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/e9bcb4/32.png) [@dfinnie](https://www.ruby-forum.com/u/dfinnie)\
**Post date:** [January 3, 2008, 10:42am UTC](https://www.ruby-forum.com/t/clipboard-command-line-utility/124823/3 "2008-01-03T10:42:33Z")

</div>

On Thu, Jan 03, 2008 at 06:09:58AM +0900, dfinnie wrote:

> I’ve been doing a lot of Python for Google’s Highly Open Participation  
> contest lately but finally found the time to make a utility I thought  
> of a few weeks ago. Basically, it allows you to pipe to and from the  
> clipboard on the command line. Example:
> 
> daniel@daniel-desktop:~$ echo ‘ruby’ | clipboard  
> daniel@daniel-desktop:~$ clipboard  
> ruby  
> daniel@daniel-desktop:~$

I’m not saying you shouldn’t write this utility – I’ve been known to  
duplicate existing utilities at times, too, sometimes with a good reason  
and sometimes for less-good reasons. However . . .

Are you aware there’s a commonly available utility for this already  
called xclip? I use it pretty extensively.

ren@kokopelli:~\> echo ‘ruby’|xclip  
ren@kokopelli:~\> xclip -o  
ruby  
ren@kokopelli:~\> cat books.txt  
Policy Made Easy  
ren@kokopelli:~\> xclip books.txt  
ren@kokopelli:~\> xclip -o  
Policy Made Easy  
ren@kokopelli:~\>

. . . et cetera.

FreeBSD:  
root@host:/\> portinstall xclip  
(assuming you use portupgrade)

Debian:  
root@host:/# apt-get install xclip

If you already knew about xclip, I’m curious why you are writing what  
amounts to a Ruby replacement for it. Are you just practicing? Do you  
want to rewrite a bunch of utilities in Ruby kinda like the Perl Power  
Tools? Do you dislike the xclip licensing?

Feel free to refuse to cater to my idle curiosity. I’m just nosy that  
way.

---

<div class="post-metadata">

**Author:** ![dfinnie](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/e9bcb4/32.png) [@dfinnie](https://www.ruby-forum.com/u/dfinnie)\
**Post date:** [January 4, 2008, 12:33am UTC](https://www.ruby-forum.com/t/clipboard-command-line-utility/124823/4 "2008-01-04T00:33:41Z")

</div>

> If you already knew about xclip, I’m curious why you are writing what  
> amounts to a Ruby replacement for it

There are probably a many reasons, I do not know why he wants to have  
this,  
but one thing which immediately comes to my mind is:

- To have the same functionality available in pure ruby, without  
depending on  
some C program like xclip. 🙂

---

<div class="post-metadata">

**Author:** ![dfinnie](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/e9bcb4/32.png) [@dfinnie](https://www.ruby-forum.com/u/dfinnie)\
**Post date:** [January 5, 2008, 2:54am UTC](https://www.ruby-forum.com/t/clipboard-command-line-utility/124823/5 "2008-01-05T02:54:49Z")

</div>

I actually did not know about xclip, I wrote the utility to use it, not  
as  
an exercise. Thanks for the link.

Do you have any other favorite command line utilities?

Thanks,  
Dan Finnie
