Here et is. Note the !is[blank] in case you had space at the end or the beginning of the text. Note also that \s+ might not do the trick depending of the quality of the text and the language. It wold count the French l'aventure as a single word instead of 2.
Note also that I put the button directly into the tiddler, which is not what you want. You’d rather use the <$tiddler> widget to select the text tiddler or use the $tiddler parameter in the <$action-setfield> widget in real code.
The handling for the “done” button is defined by the save-tiddler-actions() macro in $:/core/ui/EditTemplate. Thus, to set the wordcount when the “done” button is pressed, just add the following line at the beginning of the save-tiddler-actions() macro:
Alternatively, you could put the above line of code into a separate tiddler (e.g., $:/MyDoneActions) and then transclude that tiddler at the beginning of the save-tiddler-actions() macro, like this:
{{||$:/MyDoneActions}}
Note the use of || in the transclusion, so that the $action-setfield widget is applied to the current tiddler being saved. By putting the extra actions into a separate tiddler, it allows you to easily add actions without having to make more direct changes to the $:/core/ui/EditTemplate tiddler.
Word count is a good summary, some documents demand a minimum number of words, but it would be interesting to extract more info such a average word length, after excluding “stop words” such as “and …” what are the most common words used and how many times. Perhaps in the info tabs for authors to review. It would highlight the focus of the piece, help construct abstracts or tell you when to use a thesaurus or you are over using acronyms.
Started a new thread, and tried to delete my reply to this old thread (since it’s marked “solved” – but the old thread still shows as bumped to top of queue. So might as well add a pointer here (in this older thread) to my new variation on the question: