My current problem is to check if a note exists. If not create it with a certain template, otherwise append to it. Without any logic it isn’t possible but I will have a look and maybe try to do it via JavaScript within Drafts.
I still use it, but didn’t write many new actions since, so it didn’t evolve much.
I just made an updated version to support your use case: BearAPI 2 preview 1 action. The main difference is that it doesn’t fail the whole action if the note doesn’t exist but returns false instead.
var title = "My templated note";
var template = "My super template\n---\n";
var n = BearNote.fetch(title);
if (n === false) {
n = BearNote.create(template, { "title": title });
if (n === false) context.fail();
}
n.append(draft.content + "\n---\n");
thanks. That was quick and I could make it work and built upon that.
I have to look more into JavaScript but it can be really useful to add more logic to iOS/MacOS automations. Here is my first draft of the script.
let d = new Date()
// draft.setTemplateTag('daily-long-title', dailyLongTitle);
let title = strftime(d, `%Y-%m-%d Daily Note for %A`)
let dailyLongTitle = strftime(d, `%A, %d.%m.%Y (week %V & day: %j)`)
let tagYear = strftime(d, `%Y`)
let tagMonth = strftime(d, `%Y %m`)
var template = `
#dailies# #dailies/${tagYear}# #dailies/${tagYear}/${tagMonth}#
---
*${dailyLongTitle}*
---
### Daily Tasks
- [ ] learn vocabulary with Anki
- [ ] check calendar
- [ ] check todos
---`;
var n = BearNote.fetch(title);
if (n === false) {
n = BearNote.create(template, { "title": title });
if (n === false) context.fail();
}
n.append("\n" + draft.content);