Automatically add a value to a field based on wordcount

Depending on the attributes of a tiddler, I want to do several things when I finish editing it. I achieve all such actions through a $:/MyDoneActions tiddler tagged as System. It is called from the save-tiddler-actions() macro in $:/core/ui/EditTemplate like this:

{{||$:/MyDoneActions}}

The $:/MyDoneActions tiddler contains:

<$list filter="[<currentTiddler>get[text]splitregexp[\s+]count[]compare:integer:lt[50]]">
	<$action-listops $field="atts" $subfilter="small" />
</$list>

<$list filter="[<currentTiddler>!p1-date[]]">
	<$action-listops $field="related" $subfilter="rep" />
</$list>

The problem is that even for tiddlers with less than 50 words, ‘small’ is not added to the field ‘atts’. At the same time, for tiddlers with non-blank ‘p1-date’, ‘rep’ is added to the ‘related’ field.

How do I get TW to add the appropriate value to the ‘att’ field? Is there something wrong with the way I am computing the wordcount? May be some syntax error?

Two aspects (at least):

The current tiddler when you edit it is not the same as the current tiddler when it is saved, but instead it is a tiddler named something like Draft of 'foo'so maybe you need to extract the actual name string.

But, just running things in a listwidget doesn’t execute such actions, at least not from the text field. As far as I know, you would need to somehow execute this in the Save tiddler button.

As mark points out all actions need a trigger like a button. You can use an existing button such as done to trigger an action but you have to edit it.

However why save it when you can always calculate it?

In 5.2.3 you can add your wordcount to the subtitle with a simple tag.

If you need to use this value in a seperate list perhaps to accumulate it, you can just calculate it for each tiddler.

@twMat Thanks. In the same $:/MyDoneActions tiddler, there are other snippets like:

<$list filter="[<currentTiddler>!p1-date[]]">
	<$action-listops $field="related" $subfilter="rep" />
</$list>

And it works as expected. That is when I complete editing of any tiddler that has a non-blank p1-date field, value of ‘rep’ is added to the field ‘related’.

Also, the $:/MyDoneActions is executed from save-tiddler-actions() in $:/core/ui/EditTemplate.

I should have put this information in my question for all to see. I am doing it now.

@TW_Tones Thanks. I have added more information to the question. That hopefully answers your point. Please let me know if you need more information.

Your point is well-taken. Word count can be computed on the fly and need not be stored. But I am making changes to the value of a field based on word count.