Emacs And macOS Shortcuts

Watts Martin has an interesting post on calling macOS shortcuts from Emacs. For those who don’t know, a shortcut is sort of like an Applescript script. You can specify a sequence of actions along with some simple looping, give it a name, and call it with a single click or with Siri. If you’re interested, here’s a short introduction.

Martin wanted to capture the weather and location for Org-journal entries as well as a way to add photos to an entry. He couldn’t find a way of doing it directly from Emacs but there were shortcuts that did what he wanted. The problem was how to call them from Emacs and capture their output. Although there is an Emacs shortcuts package it doesn’t appear to have any way of capturing the output.

What to do? It turns out that there’s a shortcuts command line utility that does do what he wants so he wrote a bit of Elisp to call the command line utility and insert the results into the current buffer.

The code is simple as you can see from his post. He also shows the shortcut for picking a set of photos and returning Org links to them. This is a nice solution. Martin leverages a builtin Apple utility to do something that’s not exposed to Emacs and then uses a bit of Elisp glue to make it accessible at the Emacs level. It’s another example—if you needed one—of the power of Emacs to adapt to you rather than the other way around.

This entry was posted in General and tagged . Bookmark the permalink.