⌘ October 26, 2021

Shortcuts Tips: Getting Wisdom from a Website

Here’s a quick shortcut that I put together tonight after being inspired by @RyanMorey on Twitter. This shortcut fetches individual lines of text from the webpage that’s created and curated by Merlin Mann. I’ve linked to Merlin’s bits of wisdom in the past, and I look forward to every new addition.

Screenshot showing the action of the Get Wisdom shortcut.
You can use this screenshot to follow along with the action descriptions below.

1️⃣ After seeing that @RyanMorey’s shortcut relied on text hardcoded into an action, I thought I could probably update it to always pull from the latest collection on the web. Getting the body text of the article is trivial (using a URL action and Get Article from Safari Reader action), but filtering out the lines of text that aren’t actually bits of wisdom took a few tries. I didn’t want the shortcut to serve up the front matter, nor the section headings or footer text.

2️⃣ At first, I thought I could use RegEx to match and keep only lines of text that contained a bullet character. But after dipping into the rabbit hole that is RegEx, I realized it was more than I was ready to learn. Instead, I split the body text by new lines with a Split Text action, and then brute force attack each line (using Repeat with Each) with an If action, which collects only lines with that bullet character in a new variable. I don’t love this implementation, but since it’s just text, the shortcut still runs very quickly, and it means I was able to use only built-in actions.

3️⃣ The next action (Get Item from List) does one more filter to remove the introductory thoughts, which are also bulleted at the beginning of the document. From that final list of actual lines of wisdom, I get one random item (another Get Item from List action) and then reformat it slightly with a Match Text action to remove the bulleted list characters.

4️⃣ The final action is Show Result, which presents the final wisdom. When run from Siri, it will either display the text on screen or speak it aloud to you, depending on your Siri settings and how you initiated the shortcut.

Get the Get Wisdom shortcut → Original Version | Latest Version

Note: This shortcut, unfortunately, does not run on the Mac at the time of writing. While the Mac did recently get the Shortcuts app in macOS Monterey, some actions are not yet supported, including the Get Article from Safari Reader action on which this shortcut hinges.


This was a fun experiment to figure out how to scrape a bit of data from a webpage that wasn’t designed for serving it up in that way. I’m sure it could be adapted for similar uses on other pages.

Thanks to @RyanMorey for the initial idea and foundational shortcut, and of course to Merlin Mann for creating the document and continuing to add to it.

Shortcuts


❮ Previous post

7 Things (Which Are My Favorite iOS and iPadOS 15 Tips) This Week, 2021-10-24 October 24, 2021

Next post ❯

7 Things This Week, 2021-10-31 October 31, 2021