Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > Clipboard command line utility

Reply
Thread Tools

Clipboard command line utility

 
 
dfinnie
Guest
Posts: n/a
 
      01-02-2008
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

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

Thanks,
Dan Finnie

 
Reply With Quote
 
 
 
 
hemant
Guest
Posts: n/a
 
      01-02-2008
On Jan 3, 2008 2:39 AM, 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:~$
>
> 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 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!

>
> 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
>
> I would also like a better way to capture STDIN without blocking if
> there is no text on STDIN.
>
> Thanks,
> Dan Finnie
>
>
>




--
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

 
Reply With Quote
 
 
 
 
Chad Perrin
Guest
Posts: n/a
 
      01-03-2008
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.

--
CCD CopyWrite Chad Perrin [ http://ccd.apotheon.org ]
Leon Festinger: "A man with a conviction is a hard man to change. Tell him
you disagree and he turns away. Show him facts and figures and he questions
your sources. Appeal to logic and he fails to see your point."

 
Reply With Quote
 
Marc Heiler
Guest
Posts: n/a
 
      01-03-2008
> 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.
--
Posted via http://www.ruby-forum.com/.

 
Reply With Quote
 
Daniel Finnie
Guest
Posts: n/a
 
      01-05-2008
[Note: parts of this message were removed to make it a legal post.]

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

On 1/3/08, Chad Perrin <> wrote:
>
> 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.
>
> --
> CCD CopyWrite Chad Perrin [ http://ccd.apotheon.org ]
> Leon Festinger: "A man with a conviction is a hard man to change. Tell him
> you disagree and he turns away. Show him facts and figures and he
> questions
> your sources. Appeal to logic and he fails to see your point."
>
>


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Clipboard - Copy Image To Clipboard Mahsha Javascript 1 06-01-2009 05:06 PM
$clipboard = Gtk::Clipboard.get('PRIMARY')... under windows Dan Bishop Ruby 0 08-26-2008 01:47 PM
clipboard.setContents destroys clipboard.getContents? spunibard@gmail.com Java 2 03-02-2007 07:52 PM
Paste from clipboard when clipboard changes mid script melvynm@gmail.com Javascript 4 12-14-2004 10:59 PM
Using VB.Net or C#, utilizing the clipboard object, how to copy an MS Excel graphic from the clipboard to an image control and obtain its source reference TC ASP .Net 5 09-01-2004 04:49 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57