Save Show Notes Shortcut

My entry for the MacStories Automation April shortcuts contest is one I use almost daily.

When I go for walks, I like to listen to podcasts using Overcast and my AirPods Pro. Often I’ll want to checkout various links and products mentioned in the podcast, which are included in their show notes. 

Luckily Overcast includes an action to get show notes for the currently playing episode. Originally I wrote a shortcut to save the show notes to Drafts, but it didn’t seem like the best place to save reading material. As a heavy user of Instapaper, I realized it would be a much better place to save them.

Unfortunately the Instapaper shortcut action only take in URLs and not text to directly. Instapaper provides users with an email address that can be used for saving text, but when I tried doing that in a shortcut, Siri would tell me that I needed to unlock my phone first in order to send an email.

Siri can call URLs without needing to unlock my phone, so as a workaround, I created an If-This-Then-That recipe to send emails to Instapaper when triggered via a webhook. (Note: I tried sharing the IFTTT recipe, but it won’t let me make it public for some reason.)

I stored the IFTTT webhook API key in Data Jar to make it easier to share across other shortcuts, but it could easily be hardcoded into the shortcut or stored in a iCloud Drive file. 

Shortcut Link: https://www.icloud.com/shortcuts/075d30c36cc64f5b8107d1581d72a0ac

Screenshots:

Offline Queueing with MQTT

For a project I’m working on, I want to use MQTT as a lightweight message queue. I particularly want the ability to queue up messages in the case where the backend processor is offline, in case it crashed or is being upgraded.

I installed Mosquitto and wrote a pair of publish/subscribe scripts in Python using the paho-mqtt library. I quickly discovered that messages were not being queued if I shut down the subscriber. I tried setting the Retain flag on the messages but that only resulted in just the last message sent being queued.

Turns out there’s several things you need to do in both the publisher and subscriber to enable offline queueing:

  1. Set the QOS level to 1 or 2 in both the publisher and subscriber.
  2. Set a client ID in the subscriber
  3. Subscribe with “Clean Session” set to false

In addition, the subscriber must connect at least once before messages will start queueing up for it.

Here’s the updated sample scripts:

publisher.py

#!/usr/bin/env python

import sys
import paho.mqtt.publish as mqtt_publish

if len(sys.argv) < 3:
    print "Help: publisher.py topic-name payload"
    sys.exit()

topic = sys.argv[1]
message = sys.argv[2]

mqtt_publish.single(topic, message, hostname="localhost", qos=1)

subscriber.py

#!/usr/bin/env python

import paho.mqtt.client as mqtt
import sys

if len(sys.argv) < 2:
    print "Help: subscriber.py topic-name"
    sys.exit()

topic = sys.argv[1]

def on_connect(client, userdata, rc):
    print("Connected with result code " + str(rc))
    client.subscribe(topic, qos=1)

def on_message(client, userdata, msg):
    print(msg.topic + " " + str(msg.payload))

client = mqtt.Client(client_id="test-client", clean_session=False)
client.on_connect = on_connect
client.on_message = on_message

client.connect("localhost")

client.loop_forever()