Quick Open Action for Drafts

2019-05-21    Permalink

Just whipped up a super simple little Drafts script action which I thought I’d share. By default, Drafts opens with a blank new draft, ready to capture your thoughts. If you’ve just been working on a draft, however, it will reopen when you switch back to the app, as long as you haven’t been inactive for too long. In settings, you can adjust that time delay to whatever suits you best. When you find your own sweet spot1, it’s a fantastic feature which pretty much always does what you want without your having to think about it.

Just occasionally though, you end up on the wrong end of that delay. If you launch expecting a blank draft, and your previous one is still there, you just hit ⌘N. But what happens if you end up with a blank draft when you were expecting to reopen your previous one?2 My solution was to create a two-line script action to quickly open the most recently accessed draft3 with the keyboard shortcut ⌘O:

let recent = Draft.query('', 'all', [], [], 'accessed', true, false)[0]

It’s one of the simplest script actions I’ve made, but also one that I now use frequently. You can download it now from the Action Directory.

  1. Five minutes for me. 

  2. Drafts does offer a “focus mode” to prevent this from happening, so this action is just for when I forget to turn it on. 

  3. The action only works if you don’t edit the blank draft first. For a longer list of recent drafts, there’s a combination of built in keyboard shortcuts you can use. Just hit ⌘\ then use the right arrow key to select Recent Drafts, up and down arrow keys to navigate between them, and return to open the one you want. 


2019-04-20    Permalink

Today I’m very excited to announce the release of my first ever iOS app, Grader+. It’s a simple utility app, primarily designed for teachers marking tests and exams. It’s available on the App Store now as a free download, with a $0.99 in-app purchase to unlock the premium features.

My motivation for creating it was twofold. Firstly, it’s an app that I wanted to exist so I could use it myself. The way I mark, I go through tests question by question, writing the number of marks for each question on the paper. At the end, I then need to add up the marks for each student to work out their total mark and then record it. Grader+ is designed to help with the adding up and recording part of that. Now you might think – as a maths teacher – that I would be good at adding up, but in practice I would frequently lose count and have to start again, especially when I had to stop and re-mark something I had missed along the way. Other options include using a calculator, and just pressing the plus button every time, but that doesn’t solve the recording problem; or recording individual marks directly into a spreadsheet, a technique that can be useful if you want to analyse the breakdown of marks question by question, but is also time-consuming and difficult to do on the go. What I wanted was a way to record an individual mark with a single tap, and then save each mark quickly and easily. That core functionality was the inspiration of this app, and then the other features grew from there.

Secondly, my motivation for wanting to build an iOS app from scratch was to begin to properly learn the Swift programming language and the ways it can be used to build apps. I also wanted to get to grips with Xcode, the Mac app one uses to actually put the parts of the app together. I learnt a lot of the fundamentals of iOS app design from this process, especially UI design – a part of programming that I had never done before. I’ll talk more below about some of the resources I’ve found most helpful.

Grader+ Features

Firstly, I want to run through the basic features of the app and how it’s intended to be used, and I think it makes sense to do this screen by screen.


The counter tab of the app is where marks can be entered. By default it counts up, but this can be changed in settings if you are used to beginning from a maximum score and taking marks off. Alongside the total so far, the counter display also shows the last few marks entered (to help you keep track) as well as percentages1, grades2, and ranking. Saving a score will prompt for a student name, which is then saved, along with the score, to the scores tab.


The scores tab is where scores are recorded, and can be configured in settings to display percentages and grades and to sort the results in various ways. There is also an option to display statistics for all of the scores. The first of the premium features is available on this screen in the share button, which allows you to export the scores to a CSV file for easy importing to a spreadsheet, which is where these things usually end up.


This screen allows you to create and edit grade boundaries. They can be be entered as percentages or as marks3. The percentage for each one is the minimum threshold at which a grade should be awarded.


I’ve mentioned most of the settings already, but one notable one I haven’t is the other premium feature: dark mode! Why? Because it looks cool.

Learning Swift, iOS, and Xcode

There are a lot of great resources out there for learning how to make iOS apps, but I wanted to mention a few of the ones I found most useful. As a total beginner, I wanted to see someone actually make an app from scratch in Xcode to see what the process involved, and I discovered a course from Stanford University called Developing iOS 11 Apps with Swift, available on iTunes U, as a podcast feed, and also on YouTube. I watched the entire series, completing some of the assignments as I went along, and the lecturer, Paul Hegarty, does a really good job of explaining the ideas and techniques. The course does assume knowledge of the concepts of object-oriented programming, so go and do some reading on that first if you’re not familiar.

When I got stuck, I would google my issue, and I frequently found the solutions on one of the following websites:

In particular, I would not have been able to have figured out in-app purchases without this great tutorial.

I hope you enjoy using the app. It’s available now on the App Store, and if you want to support its development, and the development of future apps, please do unlock the premium features and throw a dollar (or a pound) my way.

  1. Requires a maximum score to be entered in Settings 

  2. Requires grade boundaries to be entered in the Grades tab 

  3. The latter only if the app knows the maximum score 

The Fragility of iMessage Conversations

2019-03-14    Permalink

A couple of times recently, I’ve had a family member or a friend come to me with a problem. At first it seems like no big deal: they accidentally deleted an iMessage conversation, and they just need to get it back. It might have some information they need, or it might have sentimental value. They look in vain for an undo button; dare I say it, they might even shake their phone. But to no avail. When I break the news to them that there is basically no solution, or that the solutions that do exist involve considerable inconvenience or drawbacks, they can be distraught, and rightly so.

Our text messages are the form of communication we have that most closely mirrors our everyday interactions with the people in our lives. The archive of these snippets of text, stretching out into the past, tells a story of the mundane and the intimate that is our lived experience. For some, the brevity of these messages makes them essentially ephemeral: a trail of crumbs we leave behind us, never returning to pick up. But for others, the unique record that they hold makes them incredibly precious, perhaps as precious as photographs, particularly when it comes to loved ones who have passed away.

With this kind of data, it’s our natural assumption that the more precious it is, the better it should be protected. Apple has made a lot of progress in this regard with services like iCloud Photo Library, which remove a lot of the worry of losing or breaking a device.1 However, it’s my contention that iMessage is where Apple is currently getting this the most wrong. Our iMessages conversations are highly valuable to us as irreplaceable personal data, but they are also far too easy to accidentally delete and very difficult to recover. A swipe and a couple of taps is all it takes.2

iCloud backup had previously solved the problem of losing your messages when you lose your phone. Since messages were stored in your iCloud backup, restoring a backup to a new device would restore all of your messages as well. Some kind of answer involving iCloud backups is what you will most often find online when you search for solutions to accidental deletion of conversations. But depending on when your last backup was, restoring your phone using a backup is likely to result in other data loss, since messages received after the time of the backup would not be contained within it. Other suggested solutions involve downloading third-party software which offers to take an unencrypted iTunes backup of your device and go digging around for your lost data. I won’t bother explaining why that’s a bad idea.

With iOS 12, the situation changed, or at least it could change. iOS 12 introduced the option – by default disabled – to store iMessages3 in iCloud (by which I mean iCloud storage not iCloud backup). In some ways, this makes things better. My full archive of messages is no longer preserved only in the iCloud backup of my oldest device. If I get a new device, or wipe and restore an old device, that archive is now synced in full. That sense of permanence, independent of a particular device, is what encouraged me to turn this option on and to recommend to others to do the same.

However, it also introduces a considerable downside. Deleting a conversation now results in it being deleted across all devices. And since it’s no longer stored in an iCloud backup, winding back the clock by restoring a backup does nothing. In 2019 I really think it’s unacceptable that an ordinary user can accidentally delete some incredibly important data and have no way to easily recover it.

So, what’s the solution to this problem? As I see it, there are two pretty simple ways Apple could improve the user experience in this regard. One is the humble undo button – even shake to undo would be better than nothing. Or they could go the way of iCloud Photo Library, and have a section where deleted conversations live for 30 days before permanent deletion. The other solution would be to have something on iCloud.com, which currently offers the ability to restore deleted files in iCloud Drive, contacts, calendars and reminders, and last but not least, Safari bookmarks!4 The fact that it is easier to restore an accidentally deleted bookmark than it is to restore all of the messages one has ever exchanged with one’s spouse, say, is just absurd.

Apple is generally pretty good at knowing the kind of digital belongings we value most and helping us to protect and make the most of them. iMessage is one where they are failing us. Let us restore them, let us back them up, and maybe let us export them to other formats without having to expose our unencrypted backups to third-party software.

  1. Insert the usual disclaimers about free iCloud storage being meagre and the importance of proper backups. 

  2. I’ve also seen people try to delete one message and hit the “Delete All” button; there is a confirmation dialogue, but it’s all too easy to breeze through without thinking. 

  3. I don’t know whether SMS are included in this. 

  4. Thank God that my bookmarks are safe from the capricious wrath of the delete button. 

Siri Shortcuts and Transport APIs

2019-03-11    Permalink

I haven’t written anything about Shortcuts since it was released last September, so I thought it was about time I share a few of the shortcuts I’ve had fun making recently and which I’m finding myself using almost every day. All of them leverage the advantages that came with the transition from Workflow, in particular the ability to both trigger them from Siri, and for Siri to natively respond with the output of the shortcut using the show results action.

They’ve also given me the opportunity to try two things I’ve been meaning to play around with: the Transport for London API, and the wonderful JSON parsing app Jayson. The TfL API is an amazingly comprehensive web API that gives information about public transport services all over London. I wanted to use it to build shortcuts related to common journeys I take.1

Line Status Report

The first one I built to allow Siri to tell me the status of the tube line I live on. So that I could experiment with the various URL endpoints offered by the TfL API, I built a small utility shortcut which takes a URL and uses the Jayson “View JSON in Notification” action so that I can quickly see the results by dragging down on the notification that appears. Jayson is one of the apps that has really embraced the rich notifications that were introduced in iOS 12.

JSON Shortcut, JSON in rich notification, JSON in Jayson

Running this shortcut with the URL


returns eleven JSON objects, each corresponding to one of the tube lines in London. For example, here is the raw JSON returned for the Bakerloo Line:

  "$type":"Tfl.Api.Presentation.Entities.Line, Tfl.Api.Presentation.Entities",
    "$type":"Tfl.Api.Presentation.Entities.Crowding, Tfl.Api.Presentation.Entities"



      "$type":"Tfl.Api.Presentation.Entities.LineServiceTypeInfo, Tfl.Api.Presentation.Entities",

Since I want to check the status of a particular line, the part I need here is the id key. Now I can query the URL


which returns the following JSON data:

    "$type" : "Tfl.Api.Presentation.Entities.Line, Tfl.Api.Presentation.Entities",
    "created" : "2019-03-05T14:58:26.59Z",
    "crowding" : {
      "$type" : "Tfl.Api.Presentation.Entities.Crowding, Tfl.Api.Presentation.Entities"
    "disruptions" : [

    "id" : "bakerloo",
    "lineStatuses" : [
        "$type" : "Tfl.Api.Presentation.Entities.LineStatus, Tfl.Api.Presentation.Entities",
        "created" : "0001-01-01T00:00:00",
        "id" : 0,
        "statusSeverity" : 10,
        "statusSeverityDescription" : "Good Service",
        "validityPeriods" : [

    "modeName" : "tube",
    "modified" : "2019-03-05T14:58:26.59Z",
    "name" : "Bakerloo",
    "routeSections" : [

    "serviceTypes" : [
        "$type" : "Tfl.Api.Presentation.Entities.LineServiceTypeInfo, Tfl.Api.Presentation.Entities",
        "name" : "Regular",
        "uri" : "\/Line\/Route?ids=Bakerloo&serviceTypes=Regular"

To get the human-readable status, I need to take the value from the lineStatuses key, then the first item of that array, then the value from the statusSeverityDescription key. In the shortcut I built to do this, I then have a few conditional statements to change the wording of the Siri’s response in the most common cases, so that it sounds nice and makes grammatical sense. So for example, if the API returns Good Service I have Siri respond with “There is currently a good service on the [line name]”, but if there are delays, she instead says “There are currently [type of delays] on the [line name]”. In other cases, I fall back to a default, “The current status of the [line name] is: [status]”. At some point, I should probably add some other conditionals for occasional statuses like Part Suspended.2

Line Status Report in Siri

Here’s the finished shortcut. The import question will ask you which line you want to use, and you just need to drag the one you want to the top of the list. Then you can add it to Siri with whatever phrase you like.

Arrivals Information

This isn’t the case on most of the London Underground network, but on the route I take to and from work, the trains are actually relatively infrequent. I have a ten minute walk from my work to the nearest station, and so ideally I want to time things so that I arrive a minute or two before my train arrives. I wanted to build a shortcut that would allow Siri to tell me how long it is until my train arrives. To do this, I used the URL endpoint


with the id of the station near my work. I first had to find out what this id was, so I used the endpoint

https://api.tfl.gov.uk/Line/{line id}/StopPoints

to list all of the stations, along with their ids, on a given line. This is a case where Jayson really comes into its own. When you open some JSON data in the app, you can use the key button in the top right to display the value for a given key for each element of an array. So using the previous URL with the id for the Bakerloo line, and opening the data in Jayson, I can use the key button to display the values for the key commonName. This makes it much easier to find the station I want, and then drill down to identify its id.

Jayson key tool

Armed with this information, I can now build the query to get the arrivals information I need. But since not all the trains arriving at the station go in my direction, I need to filter the results I get. Each item in the array returned from the arrivals endpoint represents an approaching train, and each has a key called destinationNaptanId whose value is the station id of the terminus. I wanted to filter the results using this key to reduce the list to only those going in my direction.

In the Shortcuts app, working with lists can be a little awkward at times, and things like sorting and filtering are not natively supported. However, there’s a relatively elegant way to implement a filter operation using the Repeat with Each block. Within the repeat block, you add an if block, and within the if block you put a Get Variable action with Repeat Item as the variable name. In the Otherwise section of the if block, you put the Nothing action. This means that the if block passes through the input when it passes the condition and passes nothing when it doesn’t. It’s perhaps not intuitive that it works this way, but the output of a repeat block is actually a list of all the outputs produced at the end of each repetition – in this case, only the inputs which matched the condition.

Once I’ve filtered the results, I count how many there are. If zero, Siri responds with a default “No trains currently due”. If there are more than one, I take the first and find that value of of the key timeToStation which is given in seconds, divide by 60, and round it down to the nearest minute. This is then the value that Siri replies with using the Show Results action.3

Time to Next Train shortcut

Here’s a link to the finished shortcut.

Building these shortcuts was a lot of fun, and was made much easier by the wonderful Jayson app, without which it would have involved a lot of my poring over screeds and screeds of un-indented raw JSON data. I use these actions every day to get to and from work, and being able to ask Siri “When is the next train home?” and have her quickly reply is so much better than launching an app to enter the same journey information every time.

  1. In the API documentation, it says, “To use the Unified API, developers should register for an Application ID and Key. Append the app_id and app_key query parameters to your requests.” In practice I’ve found this isn’t necessary for the very low volume of requests I’ve been making. 

  2. One of the reasons I haven’t is that the Shortcuts app still doesn’t offer an else if option in conditional blocks, necessitating awkward nested blocks as a workaround. 

  3. In my version of this shortcut, I put in the line status shortcut at the end with a Run Shortcut action, so that Siri also tells me about any disruptions after telling me about when my train is. 

Airtable API for Drafts

2018-08-08    Permalink

I experimented last year with using Airtable as my markbook1. For some reason I just find entering data into spreadsheets so incredibly dull, and the results so incredibly uninspiring, but at the same time I fully recognise that recording student data is a valuable thing to do, both for my teaching itself, and for more mundane things like writing reports. When I came across Airtable, it struck me as much more appealing, both visually and functionally. It’s a cross between a spreadsheet and a database, and it supports a large variety of different kinds of data such as files, images, and more. Its use of coloured labels and image thumbnails also makes it a much more visual experience. It also comes with a native app for iOS with native controls like switches and buttons, which makes for a really nice experience.

But as nice as the app is, both on iPhone and iPad, Airtable is primarily a web application, and the iOS app lacks a lot of the features that the web interface has. On top of that, the web interface suffers from the curse of mobile Safari. Even if you hold down on the refresh button and hit “Request Desktop Site”, basic things like scrolling just don’t work.

There are a few features I would like to see coming to the iOS app, but for the most part, it’s just basic things that involve too many taps that I would like to see improve. For example, I have a table in my Airtable base that represents pieces of homework my students have done. When I set a new piece of homework, I want to create a whole bunch of rows with the same topic, but each associated with a different student. On the web app, you can do that quite easily by copying and pasting cells, but on iOS you need to create each new row one-by-one.

What I wanted was to be able to use the Airtable app as a visually appealing front end, but to have more power on the back end of the database to add and manipulate data from iOS. But instead of building the tools to manage my markbook, I decided instead to build the tools to build the tools. Why go to such effort? Isn’t this just adding additional layers of procrastination?2 you might quite reasonably ask – to which I would probably avoid the question and attempt to change the subject. However! I did have a few reasons for wanting to do this.

Firstly, I have been working on my programming skills3, and writing a programme to interact with a database on a server is an incredibly common programming task. It brings with it common challenges such as syncing data between the local client and the remote server, formulating requests to send to the server, and parsing data from its responses into a usable format. Secondly, I wanted to create something that others could make some use of. The tools I will make for my own purposes will be far too specific for that, but building a general-purpose system has more potential use cases for a larger number of people. Thirdly, it would make my own tools easier to maintain and modify as need be, since the meta-tools from which they are built abstract away much of the complexity.4

If you read my blog regularly, you will already know about the wonderful Drafts 55, and you will also know that it offers powerful scripting via JavaScript. Drafts is the perfect app for entering and processing data, and JavaScript is probably the language that I am most familiar with at the moment, so that’s where I decided to build it. A little while after I had begun, I saw a post from Greg Pierce, the developer of Drafts, asking for input on what services people most wanted integration with in the app. Drafts already supports a large number of services, basically on two possible levels. One is as Action Steps, which are little Workflow-style drag and drop blocks, with native UI switches and buttons and text fields. These have the advantage of being easy to use, and they are great for building simple actions, but they lack flexibility, as well as some of the basic things required for programming such as conditional statements, loops, and variables. The other way that apps and services can be integrated is via scripting, and here the list of integrations is much more extensive. Being part of a fully-featured JavaScript environment means that these integrations can be part of complex programmes.

There are basically two ways that Drafts can integrate with an app or service. One is via a URL scheme, where data is sent locally on the device from one app to another. The other is via a web API, where the Drafts app sends a message to a server on the web, which then responds in some way. This is the way that Airtable works. That server might also send that information back down to its own app on the same device, or on another device. Both of these abilities – to build URL schemes, and to send API requests – are both made possible within the Drafts JavaScript environment. What struck me about Greg’s post was how many different services people were asking for in the replies, and how many of them were perfectly possible but just waiting to be built. It occurred to me that instead of asking Greg to build them all himself, the number of integrations available might increase more quickly if users created them themselves.

User-built integrations are already perfectly possible to create, and in fact a few people have created them already. Special mention goes to Oliver Guerriat, who created two really useful – though not very well documented – ones which I don’t think enough people know about. One allows easy interaction with the Bear URL scheme, and the other adds easy interaction with many of Drafts own features6. I’d like to see more of these in the future, with documentation as good as that in Greg’s Scripting Reference. I wonder if Greg would even consider linking to some of these user-build integrations in the Drafts Scripting Reference as optional add-ons?

I wanted to try to make something like this myself, and my Airtable API is the result. Using the ideas about Object Oriented Programming that I’ve been learning about recently, I’ve created a set of classes and methods for interacting with a base in Airtable. This is very much beta software, so I am sure there are bugs, and I am sure that people will suggest additional features that would improve it. One thing I would like to add in the near future is file uploads and downloads.

Here’s a link to the script in the Action Directory, and here’s a link to the script in GitHub. To use this, include an “Include Action” action step before your own script. You will also need to find out your base’s endpoint and API key from the Airtable API documentation.

Airtable API documentation

If you have any suggestions for changes or improvements, or if you find a bug, please let me know on Twitter or by Email. If you know your way around JavaScript and you want to make some changes, feel free to issue a pull request on GitHub. Below is the full documentation I’ve created. I’ve aimed to stick as closely to Greg’s style as possible.

I’m looking forward to trying this for a few other apps or services. I think next on the list might be Working Copy, an app that I absolutely love and which has an amazingly extensive URL scheme.

If you enjoyed this post, please check out my new Amazon recommendations page.


Airtable is a web-based spreadsheet and database tool which can be used to organise a large variety of different kinds of data including text, images, files, and more. The scripting interfaces below are convenience wrappers that allow easy interaction with Airtable’s REST API.

While the Airtable API offers extensive read and write access to the data stored, it does not provide metadata about the structure of databases or the types of fields. Users will need to know this information in advance to properly interact with the database.


Represents a single record in an Airtable base.

Class Functions

  • create() -> ATRecord
    • Create a new record object.
  • selectRecords(Array of ATRecord objects, field, options) -> Array of ATRecord objects
    • Present a list of records to the user for them to select one or more
    • Parameters
      • Array of ATRecord objects: all records must have been added to a table and the table updated.
      • field [string or function] : A string denoting the name of the field which should be used to represent the records in the selection list. Alternatively, pass a function which takes each record and returns a string to display. This can be used to combine multiple fields together to create the labels for the selection list.
      • options [object]: a dictionary of options with the following available keys.
        • title [string] (optional): Title to display in the prompt.
        • message [string] (optional): Message to display in the prompt.
        • type [string] (optional): Valid values are “selectMultiple”, “selectOne”, and “selectButtons”.
        • filter [function] (optional): A function to filter the records displayed.


  • id [string, readonly]
    • The unique id of the record in the Airtable base. Undefined until the record is added to a table and the table is updated.
  • table [ATTable, readonly]
    • The table to which the record belongs.
  • createdTime [date, readonly]
    • The time that the record was created. Undefined until the record is added to a table and the table is updated.


  • getFieldValue(field) -> object
    • Takes a string with the name of the field, and returns the contents of that field.
  • setFieldValue(field, object)
    • Takes a string with the name of the field, and sets the contents of the field according to the object passed.
  • getLinkedRecords(field) -> Array of ATRecord objects
    • For a field which links to records in another table, this returns all of the linked records. The table containing the linked records must have been added to the base.
  • linkRecord(field, ATRecord)
    • For a field which links to records in another table, this adds a new linked record from the given field. Existing linked records are unaffected. Note that Airtable also supports linked fields which do not allow more than one linked record.
  • update() -> boolean
    • Pushes changes to the base for a record that has already been added to a table. Returns true if successful.


Represents a table within an Airtable base.

Class Functions

  • create(name, ATBase) -> ATBase
    • Create a new table object with a given name and associated with a given base. Name must coincide exactly with an existing table on the web.


  • name [string, readonly]
  • base [ATBase]
  • records [Array of ATRecord objects]
    • All of the records associated with the table.
  • fields [Array of strings]
    • The names of the fields associated with records in the table.


  • addRecord(ATRecord)
    • Add a new record to the table. Will not be pushed to the web until update() is called.
  • selectRecords(field, options)
    • Equivalent to ATRecord.selectRecords( table.records, field, options).
  • update() -> boolean
    • Push changes to the base. Returns true if successful.


Represents an individual Airtable base.

Class Functions

  • create(name) -> ATBase
    • Create new base object with given name.


  • name [string]
  • tables [Array of ATTable objects]
    • All of the tables associated with the base.


  • getRecordWithID(id) -> ATRecord
    • Takes the unique id of a record within an associated table and returns the record object.
  1. “gradebook” for you Americans out there 

  2. Spoiler: it’s layers of procrastination all the way down. 

  3. I’ve just started reading Code Complete by Steve McConnell, and I’ve already learnt a lot of good programming lessons. 

  4. Abstracting complexity is essentially what programming is. 

  5. See here for my previous posts about Drafts. 

  6. Mind-bendingly, it seems to make the creation of actions itself scriptable! 

Fantastically Good Reminder Parser for Drafts 5

2018-07-11    Permalink

Following my recent blog post about my Fantastically Good Event Parser, which to my great delight was featured on MacStories, I received quite a few requests to create something similar for Reminders. Fantastical, which inspired the event parser, also allows you to create reminders in the system Reminders app using natural language. The interface within the app that allows you to enter calendar events also allows you to create reminders by including words like reminder, task, or todo in the text entered.

I thought about replicating this functionality within my previous action, but this didn’t feel quite right in Drafts. Adding calendar events and setting a reminder are conceptually quite different kinds of action, so I decided to build a separate action just for reminders. Being separate, I also decided that requiring a keyword like reminder or todo didn’t make much sense for this use case, so I’m diverging slightly from the traditional Fantastical functionality here.

Otherwise, it works very similarly to Fantastical. Reminders can be entered in the form Thing Tuesday 5pm !!! /p to add a reminder called Thing with a due date of Tuesday, with a reminder at 5pm that day, with high priority, and stored in my Personal reminders list. Here are some details on how the parsing works:

  • The name of the reminder is whatever is left when the date, time, priority, and list name are removed. 1
  • The date and time can be entered in pretty much any normal format. Again, I’m using chrono.js behind the scenes here. Dates without times will default to having an alert at noon.2
  • Priority is optional and can be set as !, !!, or !!!.
  • The reminder list is set using a forward slash followed by one or more letters from the beginning of the name of the list. If a matching list is not found, or if no list is specified, the reminder will go into the system default reminders list.

I’m grateful to Greg Pierce, the developer of Drafts for recently adding some functionality to the app’s scripting engine in version 5.3 in response to my request. Without these changes, I wouldn’t have been able to make this action as fully functional as I wanted it to be. Being on the the beta channel in Slack, and now in the Drafts forum, I can honestly say that Greg is one of the most responsive developers I have come across. Even when he doesn’t plan to implement a feature request immediately (or at all), he explains his reasons clearly in a way that us non-developers can understand. Thanks again, Greg.

You can find my Fantastically Good Reminder Parser in the Action Directory.

  1. Note that I’ve decided not to automatically remove words like due or by, so if you include these they will be added to the name of the reminder. I’d suggest omitting them. 

  2. The default alarm time can be changed by tweaking the script. If there’s anyone who would like the parser to interpret dates given in the standard British format of dd/mm/yyyy, you can also change the US at the beginning of the third script step to GB

Fantastically Good Event Parser for Drafts 5

2018-06-27    Permalink

I used to have an action in Drafts 5 for adding calendar events using Fantastical, the favoured calendar app of many because of its ability to interpret events entered in natural language. Fantastical allows you to enter things like Meeting on Thursday at 5pm and then generates a calendar event by parsing out the information you provided. Compared to tapping on dialog boxes and scrolling date pickers in other calendar apps, it feels fast and easy.

The way the action works is to take each line of the draft and run it through the Fantastical URL scheme. Sometimes I would run this action with a lot of different events1 which meant watching as my iPad madly bounced back and forth from Drafts to Fantastical. If I remembered, I would put the two apps in split view beforehand to speed things up, but even with the add=1 flag set in the URL scheme to avoid having to confirm each entry, Fantastical still shows an animation each time an event is entered, which slows things down.

The way apps like Fantastical actually integrate with the system calendar in iOS is via an API which allows direct manipulation of calendar events. You may have seen the Allow app to access the Calendar? prompt when first launching apps which use this. Drafts integrates this API into its scripting capabilities, and so it occurred to me recently that perhaps I could build a similar functionality within Drafts using JavaScript. This would allow me to use the system calendar app, which I prefer aesthetically over Fantastical, while retaining the ability to enter events in natural language.

What I’ve ended up creating has almost all of the same functionality as Fantastical, but since it does not rely on launching an external URL scheme, is considerably faster. You can enter multiple events, each on a different line, and have them all instantly added to your calendar without even launching another app. As with my Things Parser, I’ve leveraged the chrono.js library to do the natural language date parsing. My action supports the following things:

  • Dates and times entered in natural language2
  • Locations entered in the form at location or in location
  • Durations entered in the form 30 minutes or 2 hours3
  • Alerts entered in the form alert 30 minutes or alert 1 hour
  • The specific calendar where the event should be created in the form /family or simply /f4

Unfortunately, my script doesn’t yet support creating recurring events as Fantastical does. This currently isn’t built in to the scripting capabilities of the event object in Drafts, but I am hoping this might be added soon. When it is, I’ll be sure to update this action to support entering recurring events.

You can find my Fantastically Good Event Parser in the Action Directory.

  1. Each term, I used it to take a plain text version of my school timetable and add it to my calendar. 

  2. Events given with a date but without a time are assumed to be all-day events. Events with a given start time but no end time are assumed to be one hour long. 

  3. Note that the space is optional and that minutes and hours cannot be mixed. Minutes can be written as minutes, minute, mins, min, or m. Hours can be written as hours, hour, hrs, hr, h

  4. Your calendars will be searched for the one beginning with the string you’ve entered. If you have two calendars with the same first letter, such as tutoring and timetable, try being slightly more specific by writing /tu or /ti. If no calendar it specified, the event will be added to the default calendar. 

Drafts Actions for Markdown

2018-06-20    Permalink

Here are a couple of Drafts 5 script actions I’ve been working on recently. A while back I created an action to create Markdown links in the reference style. This allows you to use the syntax [link text][1] in the body of the text, and then [1]: url at the bottom of the document. This is nice especially in long posts for keeping the body of the text uncluttered and readable.

The script automatically inserts the correct syntax both in the body and at the end, automatically incrementing the number each time you add a new link. If there is a URL in the clipboard, it will automatically use this.

What I’ve done more recently is to create a new, and similar, footnotes action. They are mutually compatible, so the incrementing of the reference number is shared. If there is text selected when the footnote action is run, it is moved into a footnote1. What you end up with is a mixed list of links and footnotes at the bottom of your document like this:

[1]: https://wordpress.com
[2]: https://wordpress.com/pricing/
[3]: https://jekyllrb.com
[4]: https://en.m.wikipedia.org/wiki/Ruby_(programming_language)
[5]: https://en.m.wikipedia.org/wiki/Markdown
[6]: https://en.m.wikipedia.org/wiki/HTML
[7]: https://en.m.wikipedia.org/wiki/Cascading_Style_Sheets
[8]: https://shopify.github.io/liquid/
[9]: https://pages.github.com/
[^10]: If you’re a teacher, however, you can apply to get a full Developer or Team plan for free, which include unlimited private repositories and unlimited users.
[11]: https://help.github.com/articles/configuring-jekyll-plugins/
[12]: https://github.com/barryclark/jekyll-now
[13]: http://www.barryclark.co
[14]: https://www.smashingmagazine.com/2014/08/build-blog-jekyll-github-pages/
[15]: https://itunes.apple.com/gb/app/termius/id549039908?mt=8&uo=4&at=1001lsF2
[16]: https://itunes.apple.com/gb/app/screens/id655890150?mt=8&uo=4&at=1001lsF2
[^17]: Please don’t read my early commit history!
[^18]: The one time when you wish a laptop didn’t have MagSafe.
[19]: https://itunes.apple.com/gb/app/xcode/id497799835?mt=12&uo=4&at=1001lsF2
[20]: https://desktop.github.com

Drafts 5 also allows you to set custom keyboard shortcuts for actions, so I currently have ⌘K for inline link, ⌘⇧K for reference links, and ⌘⇧⌥K for footnotes. It makes writing in Markdown feel completely frictionless.

If you like writing in Markdown, I hope you find these actions useful. You can find them here and here in the Action Directory.

  1. Like so 

Fraser Speirs on BYOD ↪︎

2018-06-18    Permalink

A great series of tweets from Fraser Speirs, who ran the first one-to-one school iPad programme in the world:

It’s now entirely clear to me that BYOD is a failed idea in K-12 EdTech. A complete evolutionary dead-end.

This isn’t a platform-specific point. iPad or Chromebook, K-12 teachers, pupils, parents and schools need more consistency, predictability, control and supervision than BYOD can possible provide.

BYOD buries the cost of device management in individual staff effort. If you won’t do integration once at the school level, each teacher will do it daily at the classroom level and usually much worse.

The weaknesses of BYOD have been obvious to me in theory for at least half a decade but now we are seeing it play out in practice.

The very existence of the textbook shows we’ve understood for hundreds of years the importance of consistency in education. Teachers need to know their tools, and they need to know their students’ tools. Bring your own device is about as good a strategy as bring your own textbook.

New Blog, Same as the Old Blog

2018-06-17    Permalink

To feel a real sense of ownership, sometimes you need to put something together yourself. And that’s what I recently decided to do with this blog. When I started writing here, I had things I wanted to share, and I needed a simple and straightforward way to share them. Wordpress.com was a great place to start: it let me get a domain name, customise how my site looked, and quickly get started on writing and publishing in Markdown, without having to worry about things like hosting.

More recently, however, I started to get a hankering to tinker in more detail. There were some things about my site I wanted to tweak and change, and I realised that a lot of these features were only available in the higher price plans on Wordpress. That got me searching for alternatives, and that’s when I came across Jekyll.

Jekyll is what’s called a static site generator. At its heart, it’s a programme in Ruby that takes a directory of text files in Markdown, HTML, and CSS, and spins them together into a bunch of web pages ready to be dropped onto a web server. The Markdown files are your blog posts, the HTML describes the layout of your posts, and the CSS says how it should be styled. The term static refers to the fact that the resulting web pages don’t change after they have been generated. This is the opposite of a dynamic web page, where the information the user sees on the page is generated continuously as they move around the site, usually with reference to some database behind the scenes. In a static site, the pages are regenerated only when the site is updated, which is perfect for a blog where most updates are just new posts.

With Jekyll, adding a new post is as simple as creating a new text file in a directory. The Ruby programme runs, creates new versions of all of your pages and pushes them to a web server. You can customise the way your site looks by tweaking the CSS, and you can adjust the structure of your site by altering the HTML templates, which are supercharged with the templating language Liquid.

Another big reason for moving to Jekyll is that my site is now incredibly portable. I’ll describe how I’m hosting it below, but because it’s just a bunch of static pages, I could host it on pretty much any web server. I need a computer to run the Ruby programme, but after that it just needs to send the files to a server and its job is done until the next update. I even managed to install Jekyll on my Raspberry Pi so it could do the processing for me, and in theory, it could even act as the web server too.

Getting Started

The easiest way to get started with Jekyll is to use GitHub Pages. GitHub is the biggest host of source code on the web. You can store your code there, and manage it using a system called Git. Collections of code (called repositories) can be stored there for free if they are public, and for a small fee if they are private1. For hosting a website which is by definition public, making the source files private isn’t necessary, so the free account is all you need. Jekyll itself is completely free and open-source, so along with GitHub Pages this gives you an extremely customisable and entirely free way to create and publish your own blog! The only cost is buying a custom domain name if you want one.

The best thing about using GitHub Pages is that you don’t have to worry about running Jekyll yourself or using a web server. GitHub just gives you a repository called username.github.io, you put your source files there, and all the processing and serving goes on behind the scenes on GitHub’s own servers. Then, as if by magic, Jekyll brings your site to life at https://username.github.io. Using GitHub Pages means you’re not running the Ruby programme yourself, which in turn restricts the options you have in terms of plugins. While I found the plugins available on GitHub Pages to be more then sufficient, if you really want to tinker down at the Ruby level, you will need to look at other hosting options.

You can start from scratch and create your HTML templates and CSS styling, but if like me you’re not an export on these things, it’s best to start from what someone else has done and then make it your own. On GitHub, this is a process known as forking. I used the wonderful Jekyll Now template by Barry Clark as my starting point. He has a more detailed post on how to do this, and there are some alternative templates he also recommends as starting points. Once you’ve done some customisation, you can hook up to your custom domain name and off you go.

The Right Tool for the Job

I wanted a way of building and managing my site which was compatible with using an iPad as my primary computer. While I think I’ve found a great way of managing the site and publishing new posts directly from my iPad, I have to say that it was the Mac that really excelled with the job of helping me build the site.

What I tried first was a little crazy. I would edit my source files on my iPad, push them up to GitHub, pull them back down onto my Raspberry Pi, which I controlled via my iPad using either SSH (using Termius) or VNC (using Screens). Then I would run Jekyll on the Pi, start a local web server on my network, and view the pages on my iPad. But as any programmer will tell you, it’s really important that the cycle of change the code, run the code, look at the output, change the code needs to be as fast and efficient as possible. This method was definitely not that. For one, the Pi was slow to build the site each time: it was often taking up to 30 seconds. Having to push to GitHub for every single tiny change is also not exactly how you’re meant to use it2.

I thought I would give it a go on the Mac instead, and this turned out to be a very good decision. As someone who would have considered themselves to have moved on from the Mac to live the iOS-only lifestyle, I have to give credit where credit’s due: it was the perfect tool for the job. My wife has an old mid-2012 MacBook Air with a battery so dead that it instantly turns off if the power is disconnected3, but after a recent reformatting and installation of High Sierra, it’s running pretty well. I installed Xcode, GitHub Desktop, and Ruby via RVM on the command line. Once you’ve got Ruby set up you can install Jekyll using these instructions. A tip if you are using GitHub Pages is to run the the command gem install github-pages. This installs all of the plugins that are compatible with GitHub Pages, and allows you to see your site exactly how it will appear on the web.

So why is the Mac so good at the job of building and testing a Jekyll site? For one thing, you are working with a lot of windows at once. I had several Xcode windows open with various Markdown, HTML, and CSS files that I was working on, I had the terminal open to run Jekyll and the local web server, I had Safari open to preview the site and to read documentation, and I had GitHub Desktop open to keep track of changes and push them to my site. The combination of autosave in Xcode, plus Jekyll automatically regenerating the local site whenever it detected changes to the source files, plus the web server continuously running, meant I could tweak something in a file, wait a few short seconds for Jekyll to rebuild, refresh Safari and view my changes, all on the same machine. It made things so much quicker. It really did give me a renewed appreciation for the Mac and the things it is really good at.

Managing the Site from iOS

Having said all that, I still use an iPad as my primary computer, and I wanted a good way to maintain the site on iOS. I needed a good way to work with GitHub from the iPad, and by far the best app to do this from is the wonderful Working Copy. It’s a fantastic Git client with one of the best sets of keyboard shortcuts and one of the most extensive URL schemes I have come across in any app. I’ve been working on some Drafts actions which leverage this URL scheme, so that I can publish posts like this one directly from Drafts with a single button. They’re still a work in progress, so that’s probably a topic for another post.

Tips and Tricks

Because I was running my Jekyll blog on GitHub Pages, I was somewhat constrained in terms of how I solved certain problems. For example, I wanted to have an Archive page, and while there were plenty of plugins available which use Ruby code to automatically generate an Archive page, I didn’t have the option of running these. Instead, I had to work within the bounds of what was possible within the Liquid template language. In the end, I was quite pleased with some of the solutions I came up with.

Archive Page

With the Archive page, what I wanted was a list of year and month headings, most recent at the top, with links to each of the posts under their respective headings. I did’t want to include months were there weren’t any posts, and I didn’t want to repeat months with more than one post. Here’s the code I used:

{% for post in site.posts %}

    {% assign current_post_year = post.date | date: "%Y" %}
    {% assign next_post_year = post.next.date | date: "%Y" %
    {% assign next_post_year = post.next.date | date: "%Y" %
    {% assign current_post_month = post.date | date: "%B" %}
    {% assign next_post_month = post.next.date | date: "%B" %}
    {% assign date_id = post.date | date: "%Y-%m" %}
    {% if post.next == nil %}
        <h1>{{ current_post_year }}</h1>
        <h2 id="{{ date_id }}">{{ current_post_month }}</h2>
    {% elsif next_post_year != current_post_year %}
        <h1>{{ current_post_year }}</h1>
        <h2 id="{{ date_id }}">{{ current_post_month }}</h2>
    {% elsif next_post_month != current_post_month %}
        <h2 id="{{ date_id }}">{{ current_post_month }}</h2>
    {% endif %}

    <p><a href="{{ site.baseurl }}{{ post.url }}">{{ post.title }}</a></p>
{% endfor %}

Basically, I print the post’s year and month, unless they are the same as the next post chronologically (which is further up the page). I also added id attributes to the months to act as HTML anchors. Then I made the date stamp on each post a link to {{ site.baseurl }}/archive#{{ page.date | date: "%Y-%m" }}, so that the user can click on the date stamp and be taken straight to the right section of the Archive page. You can try it by clicking the date stamp at the top of this post or by clicking here.

Tags Page

I used a similar trick with my Tags page, which collates all the different tags I have assigned to posts. It’s built using the following code:

{% assign all_tags = site.posts | map: "tags" | uniq | sort_natural %}
<div class="posts">
{% for tag in all_tags %}
    <h2 id="{{ tag }}">{{ tag }}</h2>
    {% for post in site.tags[tag] %}
        <p><a href="{{ site.baseurl }}{{ post.url }}">{{ post.title }}</a></p>
    {% endfor %}
{% endfor %}

The first line really shows the power of Liquid as a functional language: it fetches all the posts, gets a list of their tags, removes duplicates, and sorts them into alphabetical order. Then I just loop over the tags, printing each heading – again with an id attribute – along with links to all of the pages that have that tag. At the end of each post, I then have the following code:

{% for tag in page.tags %}
    {% if forloop.last %}
        <a href="{{ site.baseurl }}/tags#{{ tag }}" class="meta">{{ tag }}</a>
    {% else %}
        <a href="{{ site.baseurl }}/tags#{{ tag }}" class="meta">{{ tag }}</a>,
    {% endif %}
{% endfor %}

This lists the tags on the post (the last without a comma) and links them to the appropriate anchor on the Tags page. Here’s an example of a link to the tag for Notes on my Tags page.

Compared to the plugins which can do things like generate individual pages for each tag, I think I actually prefer this way of doing it. I like having single Archive and Tags pages which the user could easily do a text search on.

I wanted my site to natively support link posts. I added a custom field to my post front matter called titlelink:, and then used the following code to turn the title into a link and add a visual indicator when there was text in this field:

{% if page.titlelink %}
    <a href="{{ page.titlelink }}"><h1 class="entry-title">{{ page.title }} ↪︎</h1></a>
{% else %}
    <h1 class="entry-title">{{ page.title }}</h1>
{% endif %}

Popover Footnotes

Jekyll supports footnotes out of the box, but I wanted to implement inline, popover style footnotes like this one. There’s a JavaScript plugin called Bigfoot that can do this, so I created a js directory in my repository and put the bigfoot.min.js file in there. It wasn’t initially clear to me, but it turned out that I also had to have jQuery in there as well for it to work. I then put the following code into the default.hmtl template in my _layouts directory:

<script type="text/javascript" src="{{ site.baseurl }}/js/jquery-1.8.3.min.js"></script>
<script type="text/javascript" src="{{ site.baseurl }}/js/bigfoot.min.js"></script>
<script type="text/javascript">

Images Directory

I configured my posts’ permalinks to be of the form https://polymaths.blog[/linked]/yyyy/mm/slugified-title, and so to make it easy to reference images inside a post, I set up the directory structure within my images folder to match this. FN So for example, if the URL of the post ends with /2018/06/post-title then the path of an image for that post would be /images/2018/06/post-title/image-name.jpg. This allows me to use a simple combination of liquid tags in my Markdown image links like so:

![Image name]({{ site.baseurl }}/images{{ page.url }}/image-name.jpg)

GitHub does have a notional limit on repositories of 1GB, so at some point I’ll probably have to host my images elsewhere, but for now it’s a good solution.

Final Thoughts

Rebuilding my blog with Jekyll has been great fun and I’ve learned a lot. It’s let me get to grips with some of the basics of web programming, which is something I’d like to develop further in the future. Along the way I’ve used some great tools, from my intrepid little Raspberry Pi, to my old but reliable MacBook Air, to the incredible Working Copy app for iOS.

Here’s to the new and improved PolyMaths. Now to get writing!

  1. If you’re a teacher, however, you can apply to get a full Developer or Team plan for free, which include unlimited private repositories and unlimited users. 

  2. Please don’t read my early commit history! 

  3. The one time when you wish a laptop didn’t have MagSafe.