"Automating Markdown with Taio, Part 1"

For this week’s installment of the Shortcuts Corner, I wanted to try something different and cover an app I’ve been meaning to explore more in depth for a while: Taio.

I mentioned Taio a couple times on AppStories and Connected before, and I also covered it here on MacStories Weekly when it launched in late 2020. Taio (which stands for “text all-in-one”) is a Markdown-based text editor, clipboard manager, and text automation utility all rolled into one, resulting in what ostensibly feels like the spiritual successor to Editorial. As longtime MacStories readers may remember, discovering Editorial and the possibilities offered by its visual automations was one of the pivotal moments of my writing career; for this reason, when I was first told about Taio months ago, I started following the app’s development closely and talking to its developers regarding the app’s roadmap. I said multiple times before that I wasn’t switching away from iA Writer but that I was keeping an eye on Taio; this week, I finally took some time to sit down with the app, learn about its automation features, and create my first custom actions for Markdown documents.

For today’s column, I’m going to focus on Taio as a text editor and its automation capabilities as they relate to the writing and editing environment in the app. I haven’t been able to spend enough time with Taio as a clipboard manager yet, but I plan to delve deeper into that area in the future.

My current setup in Taio.

The best way to think about Taio as a text editor is the following: imagine Editorial, but more heavily inspired by Shortcuts’ approach to automation, with fewer features than Ole Zorn’s 1.0 debut in 2013. Taio lets you create actions that can modify and interact with the contents of its Markdown text editor, allowing you to, say, access selected text, move the cursor around, insert Markdown content programmatically into a document, open links in Safari, and so forth. Like Editorial, you create these actions in a visual editor that supports drag and drop, variables, repeat loops, and conditional blocks, plus other visual scripting tools that Editorial borrowed from macOS’ Automator back in the day and which Shortcuts later popularized on iOS and iPadOS.

As Jason Snell recently argued on Six Colors in his excellent look at the state of modern Markdown text editors, Taio’s potential is somewhat hindered by its current limitations, particularly for iPad users. For instance, the current public version of the app doesn’t offer support for keybinding, which means you can’t assign keyboard shortcuts to actions; this forces you to run actions in the text editor by choosing them from a pull-down menu in the toolbar, which isn’t ideal. Speaking of the toolbar, you can’t pin individual actions as “bookmarks” for quick access; that was one of the greatest features of Editorial, and I hope the developers will consider providing users with a fully customizable toolbar in future versions of the app.

In addition to speeding up the execution of actions, my experiments with Taio this week also made me realize how some fundamental aspects of its automation tools lack the power and flexibility found in Shortcuts. Taio doesn’t come with a dynamic variable system comparable to Shortcuts’ Magic Variables, which forces you to either manually assign variables to each action’s output or rely on the ‘Last Result’ default output for the previous action. Magic Variables are often ignored by Shortcuts users because they’re tricky to explain, and the way they’re presented in the editor is somewhat hidden, although Shortcuts has gotten better at suggesting them in recent years. When I use Taio, I remember the genius behind the whole Magic Variable concept and implementation, and I miss the way Shortcuts deals with variables and action outputs.

The list of examples goes on: unlike Shortcuts, Taio doesn’t support capture groups for regular expressions; you can’t copy and paste individual steps between actions; and it’s not nearly as intuitive as Apple’s app when it comes to building visual requests for web APIs. I could also compare Taio to my favorite text editor, iA Writer, and mention how Taio doesn’t support a customizable template system, a rich selection of keyboard shortcuts for Markdown features such as links and footnotes, or content blocks, which are essential to long-form stories such as my iOS reviews. Right now, Taio can’t even sync actions between iPhone and iPad via iCloud, and there’s no Mac app yet.

In short, Taio has a long way to go, both as an automation app and full-featured Markdown text editor. At the moment, I’m still not sure if I can commit to it as the app I will use for my most important reviews and stories of the year. At the same time, however, I see in Taio the rare glimpse of something unique, different, and powerful that I don’t spot in new apps often these days.

Taio makes up for its current rough edges by returning to an idea I left behind years ago – a fully extensible Markdown editor with support for custom actions – and reimagining it with modern additions such as file and folder bookmarks, iPad multitasking, backlinks, and more. So even though Taio can’t (for obvious reasons) sport the same degree of maturity and complexity as apps like Shortcuts, iA Writer, or Drafts, it’s doing something genuinely exciting and unlike anything else on iOS and iPadOS. This is why I want to believe in the app, follow its development with future updates, and start sharing actions I’ve been building to speed up writing and editing Markdown.

In this first installment of my ongoing experiments with Taio, I’m going to share three actions I created to insert inline Markdown links, open URLs in Safari View Controller, and add footnotes to a document. Taio doesn’t currently support sharing actions via iCloud.com links; to download the actions I’ve prepared, you’ll have to click on the direct import URLs I included at the end of this post.

Let’s dive in.

Add Link

The first action I created (which was also one of the very first workflows I wrote in Editorial years ago) lets you turn text selected in the editor into an inline Markdown link using a URL previously copied to the system clipboard. I’ve always preferred inline links to reference-style ones because of their readability, and doing this in Taio’s action editor is relatively straightforward.

First, I used the ‘Get Selected Text’ action to create a named variable (called ‘Selected Text’) that uses the current text selection in the editor as a value. What’s nice about the ‘Get Selected Text’ action is that it can return different values if nothing is selected in the editor: you can choose to return an empty text string, get all text from the current editor window, or finish running the action. I chose the ‘Finish Running’ option, so the workflow doesn’t do anything else when nothing is selected in the current document.

Getting the current text selection with Taio’s actions.

Next up is one of my favorite touches in Taio, which I’d like Apple to steal for Shortcuts: a conditional block that can use a regular expression to validate its condition. The idea is simple enough: assuming text is selected, I want the workflow to continue only if the system clipboard contains a URL and not some other random text string. Taio lets us do this with one step (the process is more convoluted in Shortcuts): as you can see below, you can pick the default ‘Clipboard’ variable as ‘Value 1’ in the ‘If’ action, then choose ‘Matches Regex’ as the condition:

If a URL isn’t found in the clipboard, the action will return an error.

In the regular expression field, I pasted the single-line version of John Gruber’s excellent regex for matching web URLs, which I’ve long used for Editorial workflows, Python scripts, and shortcuts. By doing this, if Taio confirms that the clipboard does, in fact, match a URL, it’ll replace text selected in the editor with an altered version that contains the Markdown syntax for inline links. This is accomplished via the ‘Replace Selected Text’ action, which contains a named variable (our ‘Selected Text’ one) and default ‘Clipboard’ one.

Inserting a Markdown link with Taio.

The action also comes with a final ‘Show Toast’ step that displays a HUD-style error message in case the conditional block cannot validate that the clipboard contains a URL. This step is included in the ‘Else’ section of the conditional block, and it’s set to ‘Error’ mode so that you’ll get a nice big warning in the middle of the screen if you try to add a Markdown link without a URL in your clipboard.

Open Links

My second action is also based on a workflow I created in Editorial years ago, which I rebuilt in Taio using its built-in actions for smart text selection and Safari View Controller. Using my Open Links action, you’ll be able to scan the current paragraph (without having to manually select it) for URLs and pick the one you want to open in Safari View Controller from a list.

Multiple links from the same paragraph.

The idea behind this action is that I often find myself having to reopen Markdown links I’ve already added to a story, but I don’t want to switch to the HTML preview window so those raw URLs become clickable links. I prefer to stay in the Markdown editor view, and in iA Writer, that means I have to manually select a URL, copy it, and paste it in Safari’s address bar to open it. In Taio, this can be automated thanks to the app’s integration with Safari and Safari View Controller. Even better, Taio’s actions for text selection allow me to forego the manual selection process altogether, making the entire process considerably faster than other text editors.

Taio comes with a ‘Smart Select’ action that can intelligently select the closest word, sentence, or paragraph in the editor. If you click anywhere in a paragraph and run the ‘Smart Select’ action with the paragraph parameter, the entire paragraph will be instantly selected. I used this as the foundation for an action that scans the entire paragraph for URLs and, if multiple ones are found, presents them in a list for me to choose from.

When I started putting together this action, I knew from my past experience with Editorial that I first had to figure out how “cursor restoration” would work in Taio. Basically, when you run an action that deals with selecting text programmatically in the editor, you want to make sure that, by the end of the action, your original cursor position is restored so you can go back to writing or editing at the exact spot where you left off. Editorial made this possible years ago, and you can do the same in Taio by assigning two named variables to the ‘Selected Location’ and ‘Selected Length’ default variables at the beginning of an action. These variables are two numbers that represent your position in the document (if you write ‘Hello’ and place your cursor after the letter ‘e’, the selected location will be ‘2’) and the length of the selection (if nothing is selected, it’ll be ‘0’). It’s essential to save these two numbers before modifying the editor’s selection because, when we’re done opening links, we can restore the cursor’s original position using the ‘Select Range’ action, which requires these two numeric values.

By saving the cursor’s original position at the beginning of an action, we can later restore it in the editor.

After saving the original selection and confirming that a paragraph has been selected (you can use the ‘Smart Select’ + ‘Get Selected Text’ combo for this), we can use a different Taio action named ‘Text Filter’ to filter the editor’s selection and only return links contained in it. The ‘Text Filter’ action is one of the most powerful text utilities included in Taio, and it can extract (thanks to iOS’ built-in data detectors) a variety of elements such as URLs, addresses, and phone numbers; it can even be configured to match items via regular expressions with support for multi-line matching. In this case, we can use the basic ‘Link’ parameter, which will result in a list of links passed as output to the next action.

The ‘Text Filter’ action can filter text with a variety of built-in data detectors, including URLs.

At this point, the action needs to count the number of links found and operate in two different ways depending on the result: if only one link is found, it can be opened in Safari View Controller directly; if multiple links are present in the current paragraph, you have to choose the one you want to preview from a menu first, then Safari View Controller will open. To do this, we can employ a technique we’ve seen in Shortcuts before: count the number of links returned by the ‘Text Filter’ action (unfortunately, Taio is limited to counting ‘lines’, which is not as accurate as Shortcuts’ counting by ‘items’) and use a conditional block that creates two paths – one for the value returned by the ‘Count’ action being equal to ‘1’, and the other option going into the ‘Else’ section of the block. This is the kind of thing that makes more sense visually than in prose:

If multiple links are found, we can use the ‘Select from Menu’ action to present a list of links to choose from. Like in Shortcuts, you can choose to allow multiple values in the menu’s selection but, in this case, we only want to be able to select one link and pass it to the ‘Open URL’ action, which will preview the associated webpage without leaving Taio thanks to Safari View Controller.

Opening links with Safari View Controller in Taio.

At the end of the action, as I mentioned above, we can use the ‘Select Range’ step to restore the cursor’s original position and pretend we never altered the editor’s selection.

Add Footnote

The last action I put together for this week’s newsletter is another modern take on one of my most used Editorial workflows called ‘Add Footnote’. With this action, you can enter a label for a MultiMarkdown footnote, type the footnote’s text into the multi-line field, and watch as Taio automatically scrolls to the very end of the document then back to your original position and takes care of inserting the footnote’s syntax in multiple places for you.

Adding footnotes with Taio.

Like the Open Links action I shared above, this one starts by saving two separate variables for the cursor’s original position, which will be restored at the end. In MultiMarkdown, footnotes are entered with the [^footnoteLabel] syntax, which is modeled after reference-style Markdown links. For this reason, the first step is to use a ‘Text Input’ action to ask the user to type a unique label for the footnote (I could use numbers, but I prefer readable labels for additional context). The label is saved in a ‘Footnote Label’ variable, but before continuing and asking the user to enter the footnote’s text, the action needs to confirm that the current document doesn’t already contain a footnote label with the same name. To do this, we can save the current document’s text via the ‘Get Text’ action in a variable, then use a conditional block to make sure the unique [^footnoteLabel] isn’t already present in the document. If it is, Taio will return an error and stop the execution of the action:

If the [^footnoteLabel] is unique and not present in the document, the action will prompt you to enter the footnote text in a multi-line input field (which is another feature I’d like Apple to implement in Shortcuts). Then we can make some text selection magic happen: I like all my footnotes to be inserted at the end of the document, so I used the ‘Move Cursor’ action to move the selection forward by a million characters and the ‘Replace Text’ action to insert a new line, the footnote label, and its full text at the end of the document. The ‘million characters’ approach is just a workaround: my documents don’t usually span a million characters in length (if I ever end up writing that kind of story, please stop me) – it’s just a very large number that forces the cursor to jump to whatever the last character of the current document is, then insert a line break and the footnote. With this technique, you won’t be adding a million blank characters to the document: the cursor will just move to the last character (assuming, again, the document contains less than a million characters) and insert an empty line, plus the footnote.

Manipulating text selection and scroll position in Taio.

Once the footnote has been added, the action needs to return to the cursor’s original position and insert the footnote’s label as a reference. To do this, we can use the ‘Select Range’ action to restore the ‘Current Location’ and ‘Current Length’ variables set at the beginning, then run a final ‘Replace Selected Text’ action to “paste” the label where the cursor is.

I had a great time building actions in Taio this week and learning how to script its editor to recreate some of the workflows I used to rely on years ago for Editorial. In the next installments of this series, I’m going to dig deeper into footnotes, custom previews, web searches, and lots more. Stay tuned.

Download the actions:

-"Automating Markdown with Taio, Part 1"