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 comment

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.