How to Send the Contents of a Text File to the Clipboard from the Command Line in OS X?

12

1

I would like to send the contents of a text file to the OS X clipboard.

Does Mac OS X have a built in way to do this, or will I have write a script to do this myself?

Or in other words, how do I access the clipboard from the command line?

user2539

Posted 2008-09-18T19:26:50.073

Reputation: 429

Answers

5

Nevermind, figured it out.

 pbcopy < filename

  #copies contents of a text, rtf, or eps file to the clipboard


  pbpaste

  #pastes content of clipboard to stdout

user2539

Posted 2008-09-18T19:26:50.073

Reputation: 429

1That's awesome. Where did you find this info, and are there other cool conduits between CLI world and GUI world? – slim – 2008-09-18T19:32:23.680

@slim Just, for example, google the title of the question – Matteo – 2014-05-04T14:47:11.477

2

Yep, that's the way to go. Of course, you can also pipe output into it, ie, echo "test" | pbcopy.

William Keller

Posted 2008-09-18T19:26:50.073

Reputation: