70 lines
4.8 KiB
Plaintext
70 lines
4.8 KiB
Plaintext
<p><img alt="Emacs, Shortcuts, HomeKit" src="https://danpetrov.xyz/assets/emacs-shortcuts-homekit.png" /></p>
|
||
|
||
<h2 id="the-big-new-feature-in-macos-monterey">The big new feature in macOS Monterey</h2>
|
||
|
||
<p>One of the most exciting features in the latest annual release of macOS was the introduction of <a href="https://support.apple.com/en-us/HT209055">Siri Shortcuts</a> 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 <a href="https://support.apple.com/en-gb/guide/automator/welcome/mac">Automator.app</a>, or write custom <a href="https://developer.apple.com/library/archive/documentation/AppleScript/Conceptual/AppleScriptLangGuide/introduction/ASLR_intro.html">AppleScript</a> / OSAscript scripts.</p>
|
||
|
||
<p>Now, it is possible to automate practically anything not only in the macOS, but the Apple ecosystem in general:</p>
|
||
|
||
<video controls="" width="720">
|
||
<source src="https://devstreaming-cdn.apple.com/videos/wwdc/2021/10232/4/F45F16B7-D0DD-4D4D-954B-1704C1063E3C/cmaf.m3u8" type="video/mp4" />
|
||
|
||
Sorry, your browser doesn't support embedded videos.
|
||
</video>
|
||
|
||
<p>In this post I’ll also demo how you can automate anything in the Apple ecosystem from the comfort of <a href="https://www.gnu.org/software/emacs/">GNU Emacs</a>, the world’s most extensible editor.</p>
|
||
|
||
<h2 id="integrating-with-shortcuts">Integrating with Shortcuts</h2>
|
||
|
||
<h3 id="the-shortcuts-cli">The Shortcuts CLI</h3>
|
||
|
||
<p>While the new Shortcuts app is the main place for creating and sharing Shortcuts, Monterey also shipped with a new CLI tool conveniently called <code class="language-plaintext highlighter-rouge">shortcuts</code>. For example, you can run any Shortcut directly from your shell:</p>
|
||
|
||
<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>shortcuts run SampleShortcut
|
||
</code></pre></div></div>
|
||
|
||
<h3 id="shortcuts-url-scheme">Shortcuts URL scheme</h3>
|
||
|
||
<p>macOS also exposes a new URL scheme appropriately named <code class="language-plaintext highlighter-rouge">shortcuts://</code> as described in <a href="https://support.apple.com/en-gb/guide/shortcuts-mac/apd621a1ad7a/mac">the official documentation</a>.</p>
|
||
|
||
<p>For example, to open the editor for a Shortcut called <code class="language-plaintext highlighter-rouge">SayDogg</code>, it would look like <code class="language-plaintext highlighter-rouge">shortcuts://open-shortcut?name=SayDogg</code>.</p>
|
||
|
||
<h3 id="emacs">Emacs</h3>
|
||
|
||
<p>I have recently created a new Emacs package called <a href="https://github.com/DaniruKun/siri-shortcuts.el">siri-shortcuts.el</a>, which allows you to:</p>
|
||
|
||
<ul>
|
||
<li>Interactively run Siri Shortcuts with auto completion</li>
|
||
<li>Launch and search the Shortcuts gallery (there is an <a href="https://feedbackassistant.apple.com/feedback/9803481">open issue related to search</a>)</li>
|
||
<li>Launch an editor for a Shortcut</li>
|
||
<li>Use simple helper functions to make your own automations and much more</li>
|
||
</ul>
|
||
|
||
<p><img alt="Demo" src="https://github.com/DaniruKun/siri-shortcuts.el/blob/master/shortcuts-demo.gif?raw=true" /></p>
|
||
|
||
<p>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.</p>
|
||
|
||
<p><img alt="Shortcut example" src="https://danpetrov.xyz/assets/shortcut-demo.png" /></p>
|
||
|
||
<p>Next, we add the following line to our init file (e.g. <code class="language-plaintext highlighter-rouge">init.el</code>):</p>
|
||
|
||
<div class="language-emacs-lisp highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="p">(</span><span class="nv">add-hook</span> <span class="ss">'elixir-mode-hook</span> <span class="p">(</span><span class="k">lambda</span> <span class="p">()</span> <span class="p">(</span><span class="nv">siri-shortcuts-run</span> <span class="s">"SetLightStripToPurple"</span><span class="p">)))</span>
|
||
</code></pre></div></div>
|
||
|
||
<p>Now, when Elixir mode is activated, it will trigger the Shortcut!</p>
|
||
|
||
<p><img alt="Demo" src="https://i.imgur.com/AXTamcp.mp4" /></p>
|
||
|
||
<h2 id="conclusions">Conclusions</h2>
|
||
|
||
<p>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 <a href="https://twitter.com/DaniruKun">Twitter</a>!</p>
|
||
|
||
<h2 id="links">Links</h2>
|
||
|
||
<p><a href="https://github.com/DaniruKun/siri-shortcuts.el">https://github.com/DaniruKun/siri-shortcuts.el</a></p>
|
||
|
||
<p><a href="https://support.apple.com/en-gb/guide/shortcuts-mac/welcome/mac">Siri Shortcuts User Guide</a></p>
|
||
|
||
<h2 id="attributions">Attributions</h2>
|
||
|
||
<p>Emacs Logo - By Amin Bandali - https://emacsconf.org/2020/, CC BY-SA 4.0, https://commons.wikimedia.org/w/index.php?curid=97319543</p> |