# Place string into paste buffer?

**URL:** <https://www.ruby-forum.com/t/place-string-into-paste-buffer/192991>\
**Category:** Ruby\
**Created:** [August 9, 2010, 6:23pm UTC](https://www.ruby-forum.com/t/place-string-into-paste-buffer/192991 "2010-08-09T18:23:36Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![ralphshnelvar](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/e19adc/32.png) [@ralphshnelvar](https://www.ruby-forum.com/u/ralphshnelvar)\
**Post date:** [August 9, 2010, 6:23pm UTC](https://www.ruby-forum.com/t/place-string-into-paste-buffer/192991/1 "2010-08-09T18:23:36Z")

</div>

How can I copy a string to Windows paste buffer.

A google search of  
ruby “paste buffer”  
seems not to have anything relevant.

Oh … and is there a way to suck information out of the paste buffer in  
Ruby?

---

<div class="post-metadata">

**Author:** ![ralphshnelvar](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/e19adc/32.png) [@ralphshnelvar](https://www.ruby-forum.com/u/ralphshnelvar)\
**Post date:** [August 9, 2010, 6:52pm UTC](https://www.ruby-forum.com/t/place-string-into-paste-buffer/192991/2 "2010-08-09T18:52:53Z")

</div>

If your using wxruby. I am not sure if the win32 integration has a  
method.  
Most of the GUI Frameworks should have some way of accessing the  
clipboard.  
Hope this helps.

Wx::Clipboard.open do | clip |  
clip.data = Wx::TextDataObject.new(“String data”)  
end  
\*  
\*  
\*  
\*

## thanks,

Allan D.  
[http://codesnakes.blogspot.com](http://codesnakes.blogspot.com) (my blog)  
[http://www.linkedin.com/in/javaalley](http://www.linkedin.com/in/javaalley)

---

<div class="post-metadata">

**Author:** ![ralphshnelvar](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/e19adc/32.png) [@ralphshnelvar](https://www.ruby-forum.com/u/ralphshnelvar)\
**Post date:** [August 9, 2010, 7:15pm UTC](https://www.ruby-forum.com/t/place-string-into-paste-buffer/192991/3 "2010-08-09T19:15:42Z")

</div>

On Mon, Aug 9, 2010 at 11:23 AM, Ralph S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> How can I copy a string to Windows paste buffer.
> 
> A google search of  
> ruby “paste buffer”  
> seems not to have anything relevant.
> 
> Oh … and is there a way to suck information out of the paste buffer in  
> Ruby?

You might also look at win32-clipboard

[http://rubyforge.org/docman/view.php/85/1694/README.html](http://rubyforge.org/docman/view.php/85/1694/README.html)

---

<div class="post-metadata">

**Author:** ![ralphshnelvar](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/e19adc/32.png) [@ralphshnelvar](https://www.ruby-forum.com/u/ralphshnelvar)\
**Post date:** [August 9, 2010, 9:36pm UTC](https://www.ruby-forum.com/t/place-string-into-paste-buffer/192991/4 "2010-08-09T21:36:47Z")

</div>

Gordon,

Monday, August 9, 2010, 11:15:31 AM, you wrote:

GT\> On Mon, Aug 9, 2010 at 11:23 AM, Ralph S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> > How can I copy a string to Windows paste buffer.

> > A google search of  
> > ruby “paste buffer”  
> > seems not to have anything relevant.

> > Oh … and is there a way to suck information out of the paste buffer in  
> > Ruby?

GT\> You might also look at win32-clipboard

GT\> [http://rubyforge.org/docman/view.php/85/1694/README.html](http://rubyforge.org/docman/view.php/85/1694/README.html)

Gordon, may the blessings of all the gods of all religions fall upon  
your house and your family.

* * *

To those who have trouble getting the example (full example below) to  
work, try adding  
require ‘rubygems’  
before  
require “win32/clipboard”

* * *

##########################################################################

# clipboard\_test.rb (win32-clipboard)

# 

# Generic test script for those without Test::Unit installed, or for

# general futzing. You can run this example via the ‘rake example’ task.

##########################################################################  
require ‘rubygems’ # Ad this to stop – require “win32/clipboard” –  
from complaining  
require “win32/clipboard”  
require “pp”  
include Win32

puts "VERSION: " + Clipboard::VERSION

pp Clipboard.formats  
pp Clipboard.data(Clipboard::UNICODETEXT)  
pp Clipboard.format\_available?(49161)  
pp Clipboard.format\_name(999999999)  
pp Clipboard.format\_available?(9999999)

puts “Data was: [” + Clipboard.data + “]”

Clipboard.set\_data(“foobar”)

puts “Data is now: [” + Clipboard.data + “]”

puts "Number of available formats: " + Clipboard.num\_formats.to\_s

# Clipboard.empty

# puts “Clipboard emptied”

---

<div class="post-metadata">

**Author:** ![ralphshnelvar](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/e19adc/32.png) [@ralphshnelvar](https://www.ruby-forum.com/u/ralphshnelvar)\
**Post date:** [August 10, 2010, 2:42am UTC](https://www.ruby-forum.com/t/place-string-into-paste-buffer/192991/5 "2010-08-10T02:42:14Z")

</div>

Ralph S. wrote:

> How can I copy a string to Windows paste buffer.
> 
> A google search of  
> ruby “paste buffer”  
> seems not to have anything relevant.

you could pipe it into the “nircmd.exe” program, as well…
