6

Integrating Emacs with Siri Shortcuts

 2 years ago
source link: https://danpetrov.xyz/macos/emacs/lisp/2021/12/11/integrating-emacs-with-siri-shortcuts.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

Integrating Emacs with Siri Shortcuts

2021-12-11 15:00

Emacs, Shortcuts, HomeKit

The big new feature in macOS Monterey

One of the most exciting features in the latest annual release of macOS was the introduction of Siri Shortcuts to the desktop for the first time. This isn’t the first automation solution to be introduced to OS X / macOS: before, it was common to craft custom workflows and automations in Automator.app, or write custom AppleScript / OSAscript scripts.

Now, it is possible to automate practically anything not only in the macOS, but the Apple ecosystem in general:

Sorry, your browser doesn't support embedded videos.

In this post I’ll also demo how you can automate anything in the Apple ecosystem from the comfort of GNU Emacs, the world’s most extensible editor.

Integrating with Shortcuts

The Shortcuts CLI

While the new Shortcuts app is the main place for creating and sharing Shortcuts, Monterey also shipped with a new CLI tool conveniently called shortcuts. For example, you can run any Shortcut directly from your shell:

shortcuts run SampleShortcut

Shortcuts URL scheme

macOS also exposes a new URL scheme appropriately named shortcuts:// as described in the official documentation.

For example, to open the editor for a Shortcut called SayDogg, it would look like shortcuts://open-shortcut?name=SayDogg.

Emacs

I have recently created a new Emacs package called siri-shortcuts.el, which allows you to:

  • Interactively run Siri Shortcuts with auto completion
  • Launch and search the Shortcuts gallery (there is an open issue related to search)
  • Launch an editor for a Shortcut
  • Use simple helper functions to make your own automations and much more

Demo

For example, let’s create a simple automation where when opening an Elixir file / project, the color of a smart light strip in HomeKit will switch to purple and show a notification.

Shortcut example

Next, we add the following line to our init file (e.g. init.el):

(add-hook 'elixir-mode-hook (lambda () (siri-shortcuts-run "SetLightStripToPurple")))

Now, when Elixir mode is activated, it will trigger the Shortcut!

Demo

Conclusions

Of course, this is just the tip of the iceberg of what is possible with Shortcuts. I am excited to see what clever automations you will come up with, and feel free to share them with me in the comments or on Twitter!

Links

https://github.com/DaniruKun/siri-shortcuts.el

Siri Shortcuts User Guide

Attributions

Emacs Logo - By Amin Bandali - https://emacsconf.org/2020/, CC BY-SA 4.0, https://commons.wikimedia.org/w/index.php?curid=97319543


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK