Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <%*
- // ============================================================
- // TASK COMPLETION TRIGGER — Add New Mapping
- // by sqeptyk
- // ============================================================
- //
- // Run this template to add a new tag → template mapping
- // to task-trigger-listener.md without editing it manually.
- //
- // IMPORTANT: Update LISTENER_PATH below to match where you
- // placed task-trigger-listener.md in your vault.
- // ============================================================
- const LISTENER_PATH = "Templates/task-trigger-listener.md";
- // -- PROMPTS -------------------------------------------------
- const tag = await tp.system.prompt("Tag (include #, e.g. #mytag):", "");
- if (!tag || tag.indexOf("#") !== 0) {
- new Notice("Task Trigger: Tag must start with #. Aborted.");
- return;
- }
- const template = await tp.system.prompt("Template path (no .md, e.g. Templates/MyTemplate):", "");
- if (!template) {
- new Notice("Task Trigger: Template path required. Aborted.");
- return;
- }
- // -- INJECT --------------------------------------------------
- const listenerFile = app.vault.getAbstractFileByPath(LISTENER_PATH);
- if (!listenerFile) {
- new Notice("Task Trigger: Listener not found at: " + LISTENER_PATH);
- return;
- }
- const content = await app.vault.read(listenerFile);
- if (content.indexOf('"' + tag + '"') !== -1) {
- new Notice("Task Trigger: Tag " + tag + " already exists. Aborted.");
- return;
- }
- const marker = " // Add or remove entries as needed";
- const insertIndex = content.indexOf(marker);
- if (insertIndex === -1) {
- new Notice("Task Trigger: Could not find insertion point. Aborted.");
- return;
- }
- const newEntry = '\n "' + tag + '": { template: "' + template + '" },';
- const insertAt = insertIndex + marker.length;
- const updated = content.slice(0, insertAt) + newEntry + content.slice(insertAt);
- await app.vault.modify(listenerFile, updated);
- new Notice("Task Trigger: Added " + tag + " -> " + template);
- const activeLeaf = app.workspace.activeLeaf;
- if (activeLeaf) activeLeaf.detach();
- %>
Advertisement
Add Comment
Please, Sign In to add comment