Working with Ruby
Hi, I am Jan. This is my old Ruby blog. I still post about Ruby, but I now do it on idiosyncratic-ruby.com. You should also install Irbtools to improve your IRB.

Access the system clipboard with JRuby

This is my first jruby code (written for the clipboard gem) and I was quite surprised that you only need one-liners ;)

 1
2
3
4
5
6
7
def copy(text)
  Java::JavaAwt::Toolkit.default_toolkit.system_clipboard.set_contents(Java::JavaAwtDatatransfer::StringSelection.new(text), nil)
end

def paste
  Java::JavaAwt::Toolkit.default_toolkit.system_clipboard.get_data(Java::JavaAwtDatatransfer::DataFlavor.stringFlavor)
end
Creative Commons License

juwi | April 04, 2012

Looks good. Been toying with it, too a little. JRuby is Java done right ;-)