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):
- Add the icon to your dock and double click on it. Easy
- 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.
jq. This beautiful command is like awk for json. I installed it
$ sudo brew install jq
Get it's location with
# Get the location of the binary for Automator $ which jq
Create your automator workflow:
- Utilities -> Run Shell Script.
curl -s http://yourwebsite.com 2>/dev/null
-striggers silent mode, which may not be needed, but we do it anyway.
2>/dev/nullredirects stderr to the black-hole. It's just a pseudo file descriptor. Automator will detect the output on stderr and stop the workflow, so we get rid of that output.
Utilities -> Run Shell Script.
We do it again, this time use jq to parse your data.
/usr/local/bin/jq -r ..text
- We use the output of
whichfrom above because Automator doesn't have the same path as us. This way Automator can find the command.
- We use -r to ask for raw output. This gets rid of quotes around the desired string.
The last part is a selector, and should be specific to you.
Utilities -> Copy to Clipboard
Just add this to the end, no setting.
Now click File -> Export and save your app file with an appropriate name. You're done!