Daily Note templates for each weekday

Is it possible to create daily notes pre-filled with the entries from a weekly schedule for the respective weekday? Is there a plugin for this?

There are certain things that I always want to do on certain weekdays. It would be helpful if these would automatically appear when I create a daily note.

There is a plugin called Templater which could achieve this if paired with a custom script (e.g. a python or powershell script). Templater allows you to define a custom template “trigger” which gets replaced by the output of your script. As per the readme, Templater runs when you create a new note and so works well with the core Daily Notes plugin.

So if you do a few things you could have a daily note customized to the day of the week:

  • create a template file for each day of the week (e.g. “daily Monday”, “daily Tuesday” etc as separate files containing the templates you want to see each day)
  • create a script that checks what day it is, looks up your daily templates folder and reads/echoes/outputs the "daily <today>" template
  • install the Templater plugin and configure a custom template trigger and set it to run your script
  • create a template file for the Daily Notes plugin to refer to, e.g. “daily note”, and add your Templater custom template trigger to it, i.e. the text you put in the “Template Pattern” box in Templater plugin settings
  • configure the Daily Notes plugin to use your “daily note” template file

I don’t have this implemented, so I don’t have a script to share I’m afraid, but I’m a macOS user and could try to help with a python script if desired.

1 Like

Thanks @osgav - this is a bit more complicated than I hoped, but it works. Here is the Python script that I came up with. It can also be used for creating other dynamic content in daily notes.

#!/usr/bin/python3

"""Command for loading daily journal content depending.

Use this as a user defined template with the Templater plugin.

Set the template folder location in this script and in the
Templater plugin settings. You can put this script inside the
template folder and configure it as user template.

If the template folder is called "Templates", and this script
is called "journal.py", add this Templater user function:
journal = c:\python39\python.exe Templates\journal.py

Then add <% tp.user.journal() %> to your normal daily notes template.

Add templates with names like "Schedule for Monday.md" etc.
to your template folder. These will then be inserted according
to the workday.

You can also add other functions for creating dynamic content
and call these in the main() function.
"""

import sys
import traceback
from datetime import date
from pathlib import Path

template_folder = 'Templates'
template_name = 'Schedule for {weekday}.md'


def print_schedule_for_weekday():
    today = date.today()
    weekday = today.strftime('%A')
    filename = template_name.format(weekday=weekday)
    path = Path(template_folder) / filename
    try:
        with open(path, encoding='utf-8') as f:
            content = f.read()
        content = content.strip()
    except FileNotFoundError:
        try:
            with open(path, 'w', encoding='utf-8') as f:
                f.write(f'## Schedule for {weekday}\n'
                        'Please fill in the details.\n')
            content = (f"Created an empty template [[{filename}]],"
                    ' since no existing weekday template was found.')
        except Exception:
            content = ("Weekday template not found, and cannot be created."
                       " Are you sure the template folder exists?")
    if content:
        print()
        print(content)
        print()


def main():
    if sys.stdout.encoding != 'utf-8':
        sys.stdout.reconfigure(encoding='utf-8')
    print_schedule_for_weekday()


if __name__ == '__main__':
    try:
        main()
    except Exception:
        print("Error when running user template.")
        print("```")
        traceback.print_exc(file=sys.stdout)
        print("```")

Note: Updated for the new Templater syntax.

4 Likes

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.