<%* const desc = await tp.system.prompt("Brief description"); if (!desc) { return; } const dueDate = await new Promise((resolve) => { const ObsidianModal = (tp.obsidian && tp.obsidian.Modal) || require("obsidian").Modal; const modal = new ObsidianModal(app); modal.titleEl.setText("Due date"); const dateInput = modal.contentEl.createEl("input", { type: "date" }); dateInput.value = tp.date.now("YYYY-MM-DD"); dateInput.style.fontSize = "1em"; dateInput.style.padding = "0.4em"; dateInput.style.width = "100%"; modal.contentEl.createEl("p", { text: "Press Enter to set, or close to leave the due date blank.", attr: { style: "color: var(--text-muted); font-size: 0.9em; margin-top: 0.75em;" } }); const buttonBar = modal.contentEl.createDiv({ attr: { style: "margin-top: 1em; text-align: right;" } }); const okBtn = buttonBar.createEl("button", { text: "Set", cls: "mod-cta" }); let resolved = false; okBtn.addEventListener("click", () => { resolved = true; modal.close(); resolve(dateInput.value); }); dateInput.addEventListener("keypress", (e) => { if (e.key === "Enter") { e.preventDefault(); okBtn.click(); } }); modal.onClose = () => { if (!resolved) resolve(""); }; modal.open(); setTimeout(() => dateInput.focus(), 50); }); const today = tp.date.now("YYYY-MM-DD"); await tp.file.move(`Activities/Tasks/${today} Task - ${desc}`); // If a "+ New task from this note" button on another note triggered this // template, that button stashed the source note's basename on window. // Read it once, then clear it so it doesn't leak into the next task. const sourceFile = (typeof window !== "undefined" && window._pendingTaskSource) ? window._pendingTaskSource : ""; if (typeof window !== "undefined") { window._pendingTaskSource = null; } const sourcesYaml = sourceFile ? `\n - "[[${sourceFile}]]"` : " "; _%> --- type: task date: <% tp.date.now("YYYY-MM-DD") %> status: open due: <% dueDate %> closed: people: projects: classes: assignments: sources:<% sourcesYaml %> todoist_id: --- ## Task ## Notes