Giphy Search as a Custom HTML Prompt Tech Demo for Keyboard Maestro

This macro takes a search term and gives a selection of gifs from Giphy to select from. Clicking on a gif will save its URL to the clipboard (suitable for pasting into Slack or your other chat tool of choice), or option-clicking will both save the URL and download the gif directly.

Doing this in Keyboard Maestro necessitated a few goofy (“goophy?”) things to make it work:

  • I had to rely on JavaScript to insert the content from the Giphy search results (stored as a KM variable) into the HTML prompt - Keyboard Maestro only lets you pre-populate form fields with macro values.
  • Again, JS events were required for selecting the gif (no surprise since they aren’t form fields), but I was able to use KM itself to check whether the option key was down to prompt a download.
  • For my scripting, I had to rely on a combination of JXA and plain-old AppleScript. JXA was a good choice for the Giphy querying - JavaScript does very nicely with JSON parsing and iterators compared to AppleScript; but JXA still can’t deal with alias paths and the Finder can’t handle POSIX paths - so just to be able to create a unique file name it required me to use old-school AppleScript.

Ultimately, this is a great example of how Keyboard Maestro can be used to build what is essentially a mini-application. There are certainly things that perform better or give more features, but as a toolkit to string together a lot of pieces and parts, it’s fantastic.

This also makes me want to see KM expand to include web services into its vast arsenal of capabilities. Consuming JSON or even permitting variables to be stored in JSON has some real potetial as well.

Download: Giphy Search.kmmacros.zip (zip, 9220 bytes)

Twitter, Facebook

software   files   scripts

Written on March 26, 2016