Delete a field from all tiddlers

So I just tried this button to delete a field from any tiddlers that have the field and what-do-ya-know it worked. It uses a list inside a button which I don’t recall seeing documented. Did I invent something new, or does everyone already know this except me? Any caveats or side-effects?

Edit: Caveat #1 - Don’t be like me - disable timestamps unless you really want to change the modified field in every tiddler in the list.

<$button>
<$list filter="[has[revision]]">
<$action-deletefield $tiddler=<<currentTiddler>> $field=revision/>
</$list>
Delete "revision" Field
</$button>
2 Likes

Don’t think that everyone knows this but it’s a very powerful concept that many things are based off of. I like to think of list as more of a foreach for this reason. I posted about the timestamp thing recently and logged an issue for it. See here:

In case you’re inspired to build your own “Mass Updater” I’m attaching one I built a while ago that I use when I have a similar need. Obviously USE AT YOUR OWN RISK and BACKUP FIRST yada yada. It’s not fancy, and I think Mohammad’s TiddlyCommander is a vastly better version of a similar concept - but I’ve not used it and could be wrong there. Possibly useful as starter code for something of your own.

Mass Updater.tid (3.7 KB)

Amreus,

It is great if you discovered this on your own even if some of us already knew the trick.

We should always share our meaningful discoveries because we do not know who else would like to know them.

Ultimately it is being aware that actions inside a button can also be inside a list that generates the actions that occur on the click of the button. The whole list could be in an actions macro as well.

I tend to repeat the list below the button eg;

<$list filter="[has[revision]]">

</$list>

so you see listed the tiddlers will be impacted.

Another safety method is not to use [has[revision]] but [all[tiddlers]has[revision]] or
[all[tiddlers]has[revision]!is[system]]
just to be more specific.

Another feature is the ability now to interrogate the modifier variable so one button can be set to perform multiple functions with the use of ctrl alt shift etc…

Also Mohammad’s commander or other tools have a lot of batch tools as well as being a source of methods.

WARNING: You will definitely want to avoid targeting non-overwritten shadow tiddlers with this (luckily most filters start with a default set that does not include shadow tiddlers), as “deleting a non-existent field from a shadow tiddler” is one of the cooler ways of “unpacking it” - and having the regular tiddler copy be exactly the same as the shadow tiddler. UNFORTUNATELY this is a big problem when updating the core… any updated shadow tiddlers are overwritten by the (old) regular tiddlers of the same title.

1 Like

For Fun I built a smart batch button. Here and attached;

Notes:

  • you call the batch with the filter you want to use and the name of an actions macro to do on each tiddler. See the macro call at the bottom.
  • You have to write your actions-macro in this example delete-revisions-fields
  • Here I delete the revisions field (not revision because that is used by system tiddlers)
  • It lists the potentially affected tiddlers inside the button, and does nothing if clicked unless you hold the ctrl key.
  • It reports if nothing matches the filter
\define batch-actions()
<$list filter="[<modifier>match[ctrl]]" variable=nul>
   <$list filter="$(filter)$" >
      <$macrocall $name="$(action-macro)$"/>
   </$list>
</$list>
\end
\define delete-revisions-fields()
<$action-log myVar=<<currentTiddler>> />
<$action-deletefield $tiddler=<<currentTiddler>> $field=revisions/>
\end
\define smart-batch-button(filter action-macro)
<$list filter="$filter$ +[limit[1]]" emptyMessage="No tiddlers match $filter$ ''smart-batch-button''" variable=nul>
<$vars filter="$filter$" action-macro="$action-macro$">
<$button actions=<<batch-actions>> >
To apply the $action-macro$ action macro to the following tiddler(s) use ctrl-click
<$list filter="$filter$">
   
</$list>
</$button>
</$vars>
</$list>
\end

<<smart-batch-button "[has:field[revisions]]" "delete-revisions-fields">>

What do you think?