Dispatch Bulletin notification

I’m late to the Shortcuts game.1 I’ve seen others build impressive shortcuts for years but for some reason it took me until late last year to start building some of my own. And really it was my loss, because Shortcuts have long stopped being just a gimmick. They are not a serious tool to mix point-and-click with code to build some serious workflows.

This post is about an iOS Shortcut that I use to publish short posts and photos to my Micro.blog site Bulletin. I call it ‘Dispatch Bulletin’.

Context

Bulletin is built using Jekyll, meaning it’s a static website that needs to be generated each time I make a change, and the generated pages need to be hosted somewhere. Bulletin’s source code lives in a privare GitHub repo, and the site is hosted on Netlify.2

You tell Netlify to watch your site’s repo, and it will automatically build and serve your site whenever it sees a new commit in the branch of choice. It’s really cool.

Dependencies

The Shortcut relies on two third-party apps:

  • Scriptable. To run a script that identifies the local timezone and returns its TZ database name.3
  • Working Copy. Critical since that’s how the shortcut can add posts and photos to the site’s git repo.

Summary

Brief overview of how it all works. The shortcut…

  1. Receives text input.
  2. Detects the local timezone to use later in the post frontmatter.
  3. Prompts the user for file suffix. i.e., what to add after the date in the post filename.
  4. Pulls the latest updates to the repo in Working Copy.
  5. Asks the user if they want to attach a photo.
  6. If Yes, prompts the user to select the photo from Files.app and generated the body of a photo post. If No, generates a text only post.
  7. Writes the post and optional image to the repo in Working Copy.
  8. Commits changes and pushes to remote.
  9. Displays a notification that the bulletin was published.

Details

Let’s get into it.

step explanation
Step 1: Receive text input Accept text input, save value in Bulletin variable. We’ll use that later.
Step 2: Format current date and time Get current date and time in ISO 8601 format. We’ll use that later.
Step 3: Run TZIdentifier Scriptable script Run TZIdentifier script. See below for the simple code. We’ll refer to its output later.
Step 4: Ask for file suffix Prompt for the file suffix and create a text variable of the full file path. Okay you get it, I won’t keep saying “we’ll use that later”.
Step 5: Pull latest commits Pull any new commits to the local repo in Working Copy.
Step 6: Ask if you want to attach a photo Ask if I want to attach a photo to the bulletin.
Step 7: If Yes Self explanatory.
Step 8: Browse for photo then save it and stage it. Browse Files.app for the photo, save the photo to the proper path in Working Copy and stage it for commit.
Step 9: Ask for alt text Ask for image alt text.
Step 10: Create body of photo post Create the body of the photo bulletin and save it to BulletinBody variable.
Step 11: If you don't want to wattach a photo If you don’t want to attach a photo…
Step 12: Create text-only bulletin Create text only bulletin and save it to BulletinBody variable, then end the if statement.
Step 13: Save post file to repo Save BulletinBody to a Markdown file in Working Copy and stage it for commit.
Step 14: Commit and sign Commit all staged files with a simple commit message and sign the commit with the key Working Copy already has.
Step 15: Push to remote Push changes to remote.
Step 16: Show a fancy notification at the end Show a fancy notification at the end.

At this point my work is done and Netlify takes the wheel. Once the shortcut is done pushing the commit, Netlify will detect the commit to the main branch, pull it, build it, then serve it.

Appendix

Here’s the TZIdentifier script run in Scriptable:

const tz = Intl.DateTimeFormat().resolvedOptions().timeZone

function main() {
  Script.setShortcutOutput(tz)  
}

main()

Final notes

I had a lot of fun building this. It holds the highest honor an automation can receive: I use it all the time. It’s the most convenient way to publish to a Jekyll site I’ve ever worked out and it’s how I publish 9/10 posts to Bulletin.

  1. A note on capitalization. “Shortcuts” is a noun but it’s also the name of the app itself. Classic Apple. My executive editorial decision is to capitalize ’Shortcuts’ and not ’shortcut’. ↩︎

  2. From what I can tell Netlify is one of the most common ways to host a Jekyll site online besides Github Pages. It’s a really pleasant experience to set up, and they have a free tier that will work for most hobbyists like me. I have nothing but good vibes for the company. ↩︎

  3. I need to run a script for this because I need the timezone database name for… uh… Jekyll reasons, and as far as I can tell there’s no other way to get that on iOS. ↩︎