Skip to content

Instantly share code, notes, and snippets.

@evantravers
Last active Oct 3, 2020
Embed
What would you like to do?
var calendars = ["list", "of", "calendars", "I", "want", "to", "query"];
var today = new Date();
var yesterday = new Date(today.getTime() - 1000*60*60*24);
var print_event = (e) => `${strftime(e.startDate, "%R")} - ${e.title}`;
var events = calendars
.reduce((e, c) => e.concat(Calendar.find(c).events(yesterday, today)), [])
.sort((a, b) => a.startDate - b.startDate)
.reverse()
.filter(e => !e.isAllDay)
var event_template =
MustacheTemplate.createWithTemplate(Draft.find("<uuid of an appropriate template draft>").content);
var p = Prompt.create();
p.title = "Meeting Note";
p.message = "Choose an event. the current draft will be appended to the template and tagged `meeting`.";
if (events) {
p.addSelect("event", "Events", events.map(e => print_event(e)), [], false);
p.addButton("Create Meeting Note");
prompt = p.show();
if (p.buttonPressed == "Create Meeting Note") {
// process the event
event = events.find(e => print_event(e) == p.fieldValues["event"])
var data = {
"title": event.title,
"startDate": event.startDate,
"notes": event.notes
};
result = event_template.render(data);
draft.addTag("meeting");
draft.content = result + "\n" + draft.content;
draft.update();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment