``
## 3. Shortcuts
, sort everything by the order in which chapters would appear on MacStories, and back everything up to three separate locations. To build this action, I had to turn to JavaScript.
An example of how I’d write my iOS 12 review in Drafts.
One function of the Draft object in Drafts 5 is the ability to retrieve an array of drafts by querying the app for items that match a specific search string, filter, or tag (or combination of all three). Essentially, this allows you to search Drafts 5 for items that match specific conditions; items can then be iterated upon in JavaScript for additional manipulation. My action involves querying Drafts 5 with a tag filter, which returns an array of drafts that can be read in a repeat loop and appended in succession to a new variable, which then becomes the .md file to share with other apps.
The action is comprised of three steps: a JavaScript one plus two visual actions.
Let’s take a look at the full script first:
Line 1 is where the Draft.query()
function searches for all drafts that contain the “ios12” tag. If you want to use this action yourself, you’ll have to change the tag’s name between quotes. Also, as detailed in the app’s documentation, you can optionally query the app for drafts that contain a specific string of text; for the purpose of this action, I just need to find all drafts that have been assigned a certain tag.
Once the action has an array of drafts, it can sort them by name (I have to thank Greg Pierce for the suggestion here) and append each one to an empty array created on Line 11. On Line 21, all the items in the new array are then joined in a single compile
variable that is assigned the [[file]]
template tag at the end of the script. This tag allows us to reference the newly generated file in other non-script steps of the same action, and it’s one of my favorite features of Drafts 5’s JavaScript as it provides a native bridge between scripting and built-in actions.
If you look at the script closely, you’ll see that one of the first copies of the master file is saved from the script itself. On Lines 25-26, Drafts uses the FileManager object to turn the compile
variable into a file named Review.md
(again, you should change this) that is automatically saved in iCloud Drive/Drafts 5. While I would have preferred being able to save in any iCloud Drive folder via JavaScript (apps still can’t programmatically write files outside of their container without manual user input), I still end up with a plain text copy of the file backed up in iCloud Drive with just two lines of code, which is remarkable.
Both Dropbox and the share sheet are native actions in Drafts 5.
The last two steps are native actions that use the [[file]]
tag to save a compiled copy in Dropbox and Working Copy, respectively. Dropbox is a built-in action that accepts a file name and path (which you should also change) and which can be set to overwrite an existing file of the same name. I choose to replace files because I have my editing history in Drafts and Working Copy anyway; plus, I don’t want to end up with dozens of similarly named files in Dropbox.
Finally, because iOS doesn’t have a way to save data directly into another app’s container, saving the .md file to a GitHub repository in Working Copy is done via the share sheet. Just like other actions, we can use the [[file]]
tag as input for the share sheet, which will then pass the file to the Working Copy extension.
A test version of a compiled draft saved in Working Copy.
Like last year, I expect to be using GitHub a lot with my editor as a way to keep track of changes throughout the summer and work with multiple revisions of the review.
This is likely going to be the first of many actions I’ll put together to write and edit my iOS review (and future longform stories) in Drafts 5. Even though Drafts still isn’t nearly as intuitive or visual as Editorial or Workflow when it comes to automation (it still relies too much on JavaScript in my opinion; there should be more native actions that perform the same functionalities), I love the fact that I can fully customize my text editor and build actions based on tagging. Drafts 5 is the only app on iOS that can scale from being a minimalistic note-taking scratchpad to a viable BBEdit alternative powered by actions and scripts. The more I look into Drafts 5, the more I see untapped potential for serious Markdown automation; I’m excited to continue my experiments over the next few weeks.
You can download the action here.
Submit a Shortcut Request
-"Compiling and Exporting Tagged Notes in Drafts 5"