On Sunday, September 6, 2020 at 9:02:15 AM UTC-7, Logan Chin wrote:
>
> I have created a "New Tiddler" button to press for each new lecture of a 
> given class; I have designed it such that the requisite course tags/fields 
> are filled every time a new tidier is created.
> I am wondering if there is some way to automate the date in the *title* 
> of the tiddler? Or would it be possible to have a title such as 
> "Lecture#(x)" in which every click increases x by 1?
>

Try this:

1) Create a tiddler called "NewLectureButton", containing:
\define addLecture()
<$vars num={{{ [prefix<currentTiddler>sort[modified]last[]split[Lecture 
#]rest[]else[0]add[1]] }}}>
<$vars newTitle={{{ [<currentTiddler>addsuffix[ Lecture #]addsuffix<num>] 
}}}>
<$set name="newTags" filter="[<currentTiddler>]">
<$action-sendmessage $message="tm-new-tiddler" title=<<newTitle>> 
tags=<<newTags>>
   year=<<now "YYYY">> month=<<now "MMM">> day=<<now "DD">>
/>
\end
<$button actions=<<addLecture>>>New Lecture</$button>

Then, to use it:
1) Create a tiddler with a given course title (e.g., "Intro to Poly Sci") 
and tag (e.g., "IntrotoPolySci")
2) Enter whatever text you like (e.g., a course description, professor's 
name, room #, etc.)
3) Include the following somewhere in the content:
{{||NewLectureButton}}

How it works:
* The NewLectureButton tiddler displays a button that triggers an "action 
macro" (addLecture) when pressed.  This macro performs the following steps:
* "$vars num=..." calculates the next lecture number:
** Find all tiddlers that start with the course name 
(prefix<currentTiddler>)
** Get the most recent one (sort[modified]last[])
** Remove everything except the last lecture number (split[Lecture #]rest[])
** If this is the first lecture, use default number (else[0])
** Add 1 to the last lecture number (add[1])
* "$vars newTitle=..." constructs the new title by adding " Lecture #n" to 
the end of the course name (i.e., the current tiddler title)
* "$set name=newTags..." constructs a new tag from the course name, 
allowing for spaces in the course name (e.g., "Basket Weaving 101")
* The action-sendmessage create a new tiddler, opened for editing, using 
the calculated title, tags, year, month, and day

Let me know how it goes...

enjoy,
-e

-- 
You received this message because you are subscribed to the Google Groups 
"TiddlyWiki" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/tiddlywiki/79f7fd7f-d88d-4417-9104-dcd96ced707ao%40googlegroups.com.

Reply via email to