Sort in Things3

I have a list of todos in Things3 that have times as part of the title, like so:

10:00AM Travel
9:30AM Prep Travel
11:00AM Park

Like the example, the todos are not in chronological order. Is there a way to get KM to sort them and re-order by the time of day? Things can move a selected todo up or down using keyboard shortcuts. Sometimes the list is pretty long, so I'd like to automate this rather than reordering them by hand.

Thanks in advance for any insight.

Yes, but it's not trivial given you presumably also have PM times as well.

And as with anything that processes text, it depends on exactly what input you are allowing.

Lets make the following assumptions:

  • Every line starts with a time
  • Every time is of the form ?H:MMAM - one or two digits, followed by a colon, followed by two digits, followed by AM or PM.

So my process would be:

  • First change all the times to HH:MM
    • If the line starts with H: replace it with 0H:
      • Search for ^(\d): replace with 0$1
  • Then move the AM/PM to the front of the line
    • Search ^(\d\d:\d\d)([AP]M) and replace with $2$1
    • Thankfully, P comes after A alphabetically, so we don't have to revert AM/PM!
  • Now sort alphabetically
  • Now undo the changes
    • Search ^([AP]M)(\d\d:\d\d) and replace with $2$1
    • If the line starts with 0 remove it
      • Search for ^0 replace with nothing

That should do the trick.

I think I wouldn’t undo the collation-related changes at the end: Such conditioning is probably a useful byproduct. (Plus it will facilitate debugging any issues with the conditioning logic.)