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.