Custom export button

72 views
Skip to first unread message

Omit

unread,
Apr 1, 2016, 9:21:35 AM4/1/16
to TiddlyWiki
Hi,

I'd like to create a button in the sidebar that automates the following sequence of actions:

* select all tiddlers that have the "Public" tag
* export them all to JSON format

This can easily be done thanks to the instructions here
http://tiddlywiki.com/#How%20to%20export%20tiddlers
by doing a filter search [tag[Public]] and by clicking the little "export" button, but I would like that to be automated.

A solution similar to this one would be great:
https://groups.google.com/forum/#!topic/tiddlywiki/vKMkeyezxpg

Thanks in advance for your help!

PMario

unread,
Apr 1, 2016, 2:33:20 PM4/1/16
to TiddlyWiki
Hi Omit,

Try this:

\define export-to-json(tag:"public", fileName:"export.json")
<$button>
<$action-sendmessage $message="tm-download-file" $param="$:/core/templates/exporters/JsonFile" exportFilter="""[tag[$tag$]]""" filename="""$fileName$"""/>
{{$:/core/images/export-button}} export ''<$count filter="[tag[$tag$]]"/>'' tiddler(s) tagged: "$tag$" to "$fileName$"
</$button>
\end

<<export-to-json tag:"public" fileName:"asdf.json">>

It creates a macro named: export-to-json
The macro has 2 predefined parameters: tag, fileName. They can be redefined with the macro call. see the last line.
The macro also produces a rather long button eg: [export 1 tiddler(s) tagged: "public" to "asdf.json"]
This can be made shorter, by deleting the stuff you don't need.

the following macro creates a short button with a tooltip text

\define export-to-json(tag:"public", fileName:"export.json")
<$button tooltip="""export tiddler(s) tagged: "$tag$" to "$fileName$" """>
<$action-sendmessage $message="tm-download-file" $param="$:/core/templates/exporters/JsonFile" exportFilter="""[tag[$tag$]]""" filename="""$fileName$"""/>
{{$:/core/images/export-button}} (<$count filter="[tag[$tag$]]"/>)
</$button>
\end


have fun!
mario

Reply all
Reply to author
Forward
0 new messages