Getting a REST api into your Mac clipboard

Automator is handy. It's a visual replacement for stringing together commands with pipes. Suppose you have an exposed REST endpoint which provides JSON data and you want to get some of this information into your clipboard. You can create an automator workflow which does this. All you have to do is execute the workflow. You can execute the workflow in two ways (that I've found useful):

  1. Add the icon to your dock and double click on it. Easy
  2. Execute the app with spotlight, just search and press enter.

Sweet. So how?

First, find your endpoint and test it out with cURL. You can find this url using Firefox or Chrome's inspect element/network tab. Look at the requests, pick it out, and right-click to copy the url/curl command.

Next install jq. This beautiful command is like awk for json. I installed it with Homebrew.

$ sudo brew install jq

Get it's location with which:

# Get the location of the binary for Automator
$ which jq

Create your automator workflow:

  1. Utilities -> Run Shell Script.

bash curl -s http://yourwebsite.com 2>/dev/null

We do it again, this time use jq to parse your data.

bash /usr/local/bin/jq -r .[0].text

Just add this to the end, no setting.

Now click File -> Export and save your app file with an appropriate name. You're done!