Periodic Notes + Templater - Automatically create periodic notes

I created this code to automatically create daily/weekly/monthly/yearly notes.

Every time you open Obsidian it will check if there is already a file for the day/week/month/year using the patterns and folder path you give, and if there isn´t, it will automatically create one.

You can also use Templater’s “Folder Templates” to automatically apply the templates you need for each file.

<%*
async function createIfNotExists(tp, filepath){
	if (!(await tp.file.exists(filepath))){
		app.fileManager.createAndOpenMarkdownFile(filepath)
	}
}

await createIfNotExists(tp, "Journal/Daily Journal/" + tp.date.now("YYYY/YYYY-MM-DD") + ".md")

await createIfNotExists(tp, "Journal/Weekly Journal/" + tp.date.now("YYYY/gggg-[W]ww") + ".md")

await createIfNotExists(tp, "Journal/Monthly Journal/" + tp.date.now("YYYY/YYYY-MM") + ".md")

await createIfNotExists(tp, "Journal/Yearly Journal/" + tp.date.now("YYYY") + ".md")
%>

How to use

  • Create a new file. (I named mine “Templater Startup”)
  • Copy the code inside.
  • Adjust the folders and file name patterns according to your periodic notes configuration.
  • On Templater settings, scroll down to “Startup Templates” and add the file.
9 Likes

This is amazing!!!

Hi,

I find this amazing. Though, I run into an issue every time I try and use the startup template. I work on Mac. Maybe the problem is that I need to change some piece of code to adapt it to Mac and I am not familiar with javascript.

So the error I run into most of the time seems to be a path problem. Instead of going into the path I set as “Journal/DailyNote”, for example, the function goes into the templates folder and there it looks for the path I define. Doing so, it doesn’t recognise the path I defined and therefore creates that path inside the templates folder. In addition, the folder templates I defined for each path sometimes work and sometimes don’t.

Here below the code I am using in my TemplaterStartup:

<%*
async function createIfNotExists(tp, filepath){
	if (!(await tp.file.exists(filepath))){
		app.fileManager.createAndOpenMarkdownFile(filepath)
	}
}

await createIfNotExists(tp, "Journal/DailyJournal/" + tp.date.now("YYYY/DD-MM-YYYY") + ".md")

await createIfNotExists(tp, "Journal/WeeklyJournal/" + tp.date.now("YYYY/gggg-[W]ww") + ".md")

await createIfNotExists(tp, "Journal/MonthlyJournal/" + tp.date.now("YYYY/MM-YYYY") + ".md")

await createIfNotExists(tp, "Journal/QuarterlyJournal/" + tp.date.now("YYYY-[Q]Q") + ".md")

await createIfNotExists(tp, "Journal/YearlyJournal/" + tp.date.now("YYYY") + ".md")
%>

Looking forward to seeing if any of you guys can find a solution to my problem. (:

Cheers

An update on my problem. I understood that the main problem in the behaviour of my periodic note startup is that it goes and check the last folder I had opened before closing obsidian. Does anyone has a suggestion on how to fix this?

Thank you so much for this - my use of Weekly and Quarterly notes was hit or miss because I would forget to create them. Now they are just sitting there waiting for my input - this has been the push I needed! Thanks!

I know this is way late, but I ran into the exact same issue. Here’s how I fixed it.

<%*
async function createIfNotExists(tp, filepath){
	if (!(await tp.file.exists(filepath))){
		app.vault.create(filepath,"")
	}
}

await createIfNotExists(tp, "/Daily/" + tp.date.now("YYYY-MM-DD") + ".md")

await createIfNotExists(tp, "/Weekly Priorities/" + tp.date.now("gggg-[W]ww") + ".md")
%>

Basically I replaced app.fileManager.createAndOpenMarkdownFile(filepath) with app.vault.create(filepath,"").

Also, I added a / in front of the directories I wanted to save the new files in. See the createIfNotExists function calls.

Hope this helps!