This is a Templater Startup Script for use in Obsidian.
Each time Obsidian is opened, Templater runs the script to see if a weekly, monthly, quarterly, and yearly file exists for the current date. If one exists, it moves on, if not, it creates the file using the appropriate template, in the appropriate place.
<%*
let wk = tp.date.now('GGGG-[W]WW');
let mnth = tp.date.now('MM MMMM');
let qrtr = tp.date.now('Qo [Quarter]');
let yr = tp.date.now('YYYY');
let template = '';
if (!tp.file.exists(wk)) {
template = tp.file.find_tfile('Periodic Note - Weekly');
await tp.file.create_new(template, wk);
};
if (!tp.file.exists('[[Personal/Journal/' + yr + '/' + qrtr + '/' + mnth + '/' + mnth + ']]')) {
template = tp.file.find_tfile('Periodic Note - Monthly');
await tp.file.create_new(template, yr + '/' + qrtr + '/' + mnth + '/' + mnth);
};
if (!tp.file.exists('[[Personal/Journal/' + yr + '/' + qrtr + '/' + qrtr + ']]')) {
template = tp.file.find_tfile('Periodic Note - Quarterly');
await tp.file.create_new(template, yr + '/' + qrtr + '/' + qrtr);
};
if (!tp.file.exists('[[Personal/Journal/' + yr + '/' + yr + ']]')) {
template = tp.file.find_tfile('Periodic Note - Yearly');
await tp.file.create_new(template, yr + '/' + yr);
};
%>
Hey, does this still work for you? I'm trying to get this running on my setup and it's not doing anything.
EDIT: So I got it to work, one thing to note with this is that if you specify a file path in the name bit of
await tp.file.create_new()
, it will create the file relative to your default new file location. In my case it was my inbox file.