Using the OSX clipboard from the command line

The OSX pbcopy terminal command, which adds “stuff” to the clipboard to be pasted later, is really useful. For example, to download some webpage and put the HTML source in the clipboard:

curl -s http://example.com/ | pbcopy

Here’s a WordPress example; want to get some fresh API salts and keys for a wp-config.php? Try this:

curl -s https://api.wordpress.org/secret-key/1.1/salt/ | pbcopy

Want to be notified when the download and copy are complete? Add the say command, like this:

curl -s https://api.wordpress.org/secret-key/1.1/salt/ | pbcopy; say 'Ready to paste';

I use DTerm, which is an excellent little “popup terminal” which inherits the current context, and these commands are super handy here.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>