Last Updated: February 25, 2016
·
12.49K
· weppos

Ruby pbcopy and pbpaste

pbcopy and pbcopy are two handy Mac OS X command line utilities to copy and paste content to the Clipboard.

The following Ruby methods provides access to the same utility using Ruby.

def pbcopy(input)
  str = input.to_s
  IO.popen('pbcopy', 'w') { |f| f << str }
  str
end

def pbpaste
  `pbpaste`
end

To make them available in IRB, add them to your ~/.irbrc file.

1 Response
Add your response

This doesn't seem to work for me. Is there anything special you need to do for mavericks? Thanks!

over 1 year ago ·