Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- TASK COMPLETION TRIGGER FOR OBSIDIAN
- by sqeptyk
- Automatically fire a Templater template when you check off a task
- in the Tasks plugin — including in Reading mode.
- No custom plugins required. Works with Templater's startup system
- and Obsidian's native vault event API.
- HOW IT WORKS
- A startup template registers a listener on vault file changes.
- When a file in your watched folder is modified, it diffs the old
- and new content to detect a newly completed task. If that task
- contains a mapped tag, the corresponding Templater template fires
- automatically.
- REQUIREMENTS
- Obsidian
- Templater plugin (latest)
- Tasks plugin (optional but intended)
- FILES
- task-trigger-listener.md
- The core listener. Add to Templater Startup Templates.
- Edit WATCH_FOLDER and TASK_TAG_MAP to match your setup.
- add-task-trigger.md
- Companion template. Run it to add new tag -> template
- mappings without editing the listener manually.
- SETUP
- Place task-trigger-listener.md anywhere in your vault.
- Open Templater settings.
- Go to "Startup Templates" and add task-trigger-listener.md.
- Open task-trigger-listener.md and edit the configuration:
- WATCH_FOLDER
- The folder containing your task notes. Only files inside
- this folder will be watched. Example: "TASKS" or "LOGS"
- TASK_TAG_MAP
- Maps tags to templates. Add one entry per tag:
- "#yourtag": { template: "Templates/YourTemplate" },
- The template path is relative to your vault root, no .md.
- Place add-task-trigger.md in your templates folder.
- Update LISTENER_PATH inside it to point to wherever you
- put task-trigger-listener.md.
- Restart Obsidian.
- USAGE
- Add a tag to any task in a note inside your watched folder:
- - [ ] Do something #yourtag
- Check it off. Your template fires automatically.
- To add new mappings, run add-task-trigger.md from the
- Templater command palette. It will prompt you for the tag
- and template path, then inject the entry into the listener.
- IMPORTANT NOTES
- Tasks must live inside the WATCH_FOLDER to trigger.
- Tasks on your dashboard or in other folders will be ignored.
- The listener diffs file content on every save, so it only
- fires when a task goes from unchecked to checked, not on
- every file edit.
- Only one template fires at a time. If you complete multiple
- tagged tasks in rapid succession, the processingTask flag
- prevents double-firing. Complete them one at a time.
- Works in Reading mode, Live Preview, and Source mode.
- ADDING YOUR OWN TEMPLATES
- Your Templater template fires just like any other — it has full
- access to tp.system.prompt, tp.system.suggester, and all other
- Templater functions. Build your prompts and output logic the
- same way you normally would.
- The template is responsible for creating its own output file.
- The listener just fires it; what it does is up to you.
- TROUBLESHOOTING
- Listener not loading?
- Check Templater settings -> Startup Templates.
- Restart Obsidian after adding it.
- Check the developer console (Ctrl+Shift+I) for errors.
- Template not firing after task completion?
- Make sure the task note is inside WATCH_FOLDER.
- Make sure the tag in the task exactly matches the tag
- in TASK_TAG_MAP, including the # symbol.
- Check that the template path in TASK_TAG_MAP is correct
- and the file exists in your vault.
- Template fires but errors out?
- Open the developer console and check for "Task Trigger"
- error messages.
- LICENSE
- Do whatever you want with this. Credit appreciated but not
- required. If you improve it, share it back.
Advertisement
Add Comment
Please, Sign In to add comment