May 27, 2018 at 10:57 AM by Dr. Drang
While looking through the Drafts scripting documentation for help with another idea for an action, I found a couple of Editor functions that I hadn’t noticed before. One of them led to a big improvement to my TaskPaper action group.
As explained in this post, I use Drafts now for handling TaskPaper task lists on my iPhone and iPad. Drafts has some nice built-in features for TaskPaper lists, and its extensibility through actions allows more features to be added. I wrote a handful of actions geared toward my use of TaskPaper, and added them to the Drafts Action Directory, a repository of community-created actions. You can download them from here.
One of the actions in my TaskPaper group worked as a toggle to add/remove blank lines between tasks. I keep my lists in a format that looks like this,
with no blank lines between projects except for the Archive section at the end. This is great for keeping the list tight but is a problem when I want to rearrange projects to bring the more important ones to the top. Drafts has an Arrange Mode which is perfect for this sort of thing, but it requires blank lines delimiters to define text groupings that can be moved as blocks.
Originally, I made an Un/Block action, which added or removed blank lines between projects, depending on the list’s current state. My rearranging workflow was this:
- Tap Un/Block to add the blank lines.
- Tap the Arrange Mode button at the bottom of the screen to enter Arrange Mode.
- Rearrange the projects.
- Tap the Un/Block button to remove the blank lines.
This worked well but was a little clumsy. Then I saw the
arrange functions in the Drafts Editor library. The
showArrange function wasn’t quite what I needed, but the
arrange function was perfect. It takes text as an argument, stops the flow of the script while the user rearranges it, then returns the rearranged text.
arrange, I was able to change the script of the Un/Block action into this:
It adds the blank lines in Line 14, lets the user rearrange the blocks in Line 18, and then removes the blank lines in Line 20 (Line 21 restores the blank line above the Archive section). Now the rearranging happens within the execution of the script, so I’ve renamed the action Rearrange. The workflow is reduced to two steps:
- Tap Rearrange.
- Rearrange the projects.
This is not just faster, it’s more natural because the action is named for what I really want to do and all the necessary-but-incidental format fiddling happens behind the scenes.
So, yeah, reading the documentation can be helpful. I have a sense the
dictate functions, which are also things I missed when I first looked in the Editor section, will be finding their way into my scripts soon.