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

Gem: clipboard

The clipboard gem allows you to access the clipboard on Liunx, MacOS and Windows.

The focus is on simple text. You can copy a string with Clipboard.copy("string") and paste it with Clipboard.paste. That’s it ;). Basically. Now let’s take a closer look at the specific platforms.


For Linux support, the little utility xclip is needed, you can install it on ubuntu with sudo apt-get install xclip

Furthermore, you can choose, from which clipboard you want to paste (default is PRIMARYCLIPBOARD). copy copies to all clipboards in Clipboard::CLIPBOARDS. For example: Clipboard.paste :primary


On MacOS, everything works fine :).


I’ve fought with the Win32API and still not all problems are solved (e.g. pasting with 1.9). Copying should be no problem, but you need the clip.exe program (installed by default since Vista).Now using ffi, feedback needed if it is working as expected ;).

Creative Commons License

grosser | October 04, 2010

nice to have this implemented cross-platform!