How to use multi-line input prompt to add several tasks at once ? #689
Replies: 1 comment
|
Sorry for the long silence on this one. The Task toggle wraps the WHOLE capture once, so multi-line input turns into a single Setup:
module.exports = async (params) => {
const { app, quickAddApi } = params;
const targetPath = "Tasks.md";
const raw = await quickAddApi.wideInputPrompt("Enter tasks (one per line)");
const lines = (raw ?? "")
.split("\n")
.map((l) => l.trim())
.filter(Boolean);
if (lines.length === 0) {
params.abort("No tasks entered.");
return;
}
const file = app.vault.getAbstractFileByPath(targetPath);
const existing = file ? await app.vault.read(file) : "";
const existingSet = new Set(existing.split("\n").map((l) => l.trim()));
const fresh = lines.filter((l) => !existingSet.has(`- [ ] ${l}`));
if (fresh.length === 0) {
params.abort("All of those tasks are already in the note.");
return;
}
params.variables.tasks = fresh.map((l) => `- [ ] ${l}`).join("\n");
};
Running it opens a multi-line box; type one task per line. I tested it end to end - entering: into a note that already had If you'd like a native "one task per line" capture option, that's a fair feature request to open - but the macro above does the job. |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Hi,
I’m trying to add multiple tasks in a file at once using multi-line prompt, each task being on its own line.
I use capture with task enabled but all lines from my input are added to the same task instead of inserting
- [ ]before each line.Any idea how to do that ?
Bonus: Possible to write a script to check if a task already exist and only add the non-existent ones ? Where could I start ?
All reactions