Total word count for selected drafts

I would like to add up the word count for selected drafts. After selecting drafts, if I choose operations and Run action, the action is executed on one draft at a time, showing me the number of words in each note. How to get the sum? Some sort of looping construct is needed with all selected drafts. Is this possible? Thanks.

Interesting question. There’s no way to access the “selected drafts” from the draft list from within an action, so there would be no way to calculate that information in an action.

Probably not ideal, but the best way to do that right now would be to use the “Merge” feature to create a new draft that merged your selected drafts - then you could get the character/word count of the combined entity. If you select “Do not move” in the options, it will not impact your existing drafts.

Thanks for the suggestion. As an example of another use-case for looping through many drafts, I had interest in writing a script that searches all drafts in a workspace (or drafts with a matching tag) and plucks out unfinished tasks. The resulting list of tasks could then be shipped out to one’s favorite task manager app.

I’ve just added an example action to my MGCheckListPrompt Action Set that does this for you; it’s called “Combined Word Count”. It requires Drafts 20.1 or later. When run, it will:

  1. Show a list of all the drafts in the current workspace, with checkboxes beside each one. Feel free to uncheck whichever drafts you’re not interested in.

  2. When you click the “Word Count” button, it’ll tell you the combined word count for all the drafts that were checked in the list.

You can edit the “Combined Word Count” example to see how it works, and do other things that require choosing a set of drafts first.

1 Like

Querying and looping over drafts is easily done in script. If your set of drafts is based on a workspace, no problem (as Matt’s example demonstrates).

You just cannot current get the “selected drafts” from the draft list.