How to run a macro when a button is clicked?

Posting my final solution here, which someone might find useful.

<$button> export
<$set name="filter" filter="[[Test]get[text]]">

<$action-sendmessage
   $message="tm-download-file"
   $param="$:/core/templates/exporters/JsonFile"
   exportFilter=<<filter>>
   filename="tiddlers.json" />

</$set>
</$button>

How?

If you create a tiddler Test and fill it with some filters. Like

[prefix[$:/core/images/]]
[tag[TableOfContents]]

Then clicking on the button, which is given above, will export the tiddlers that match the filters in JSON format.

Why? (Use case)

I am exploring different ideas to easily sync my configuration across all my TWs.

One solution I have in mind goes like this

  1. Create a master copy of TW
  2. Configure it to your liking
  3. Collect the list of system and shadown tiddlers you configured in a tiddler, like Config-List, using filters
  4. Export all the tiddlers in JSON using the button given above and import into new TWs

Using explicit filters in Config-List means I will not export frivolous shadow tiddlers.