-
I would like to obtain all unfinished to-do items under the root directory. Is there a way to do this through an API or some other means? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
|
I want to develop a task script to automatically extract the to-do items from the content and perform operations such as grouping, display, and filtering. |
Beta Was this translation helpful? Give feedback.
-
|
@ZangXincz You can extract todo items from Trilium using the backend script API. Todo checkboxes are stored as HTML with a specific structure: <ul class="todo-list">
<li>
<label class="todo-list__label">
<input type="checkbox" disabled="disabled"> <!-- unchecked -->
<span class="todo-list__label__description">Task text</span>
</label>
</li>
</ul>Here's a backend script example to extract all unchecked todos under a root note: // Create as a code note, run manually or with #run=backendStartup
const notes = api.searchForNotes('note.type = "text" AND ancestors.noteId = "YOUR_ROOT_NOTE_ID"');
const todos = [];
for (const note of notes) {
const content = note.getContent();
const $ = api.cheerio.load(content); // cheerio is built-in
$('ul.todo-list li').each((i, elem) => {
const $elem = $(elem);
const checkbox = $elem.find('input[type="checkbox"]');
const description = $elem.find('.todo-list__label__description').text();
const isChecked = checkbox.attr('checked') === 'checked';
if (!isChecked) {
todos.push({
noteId: note.noteId,
noteTitle: note.title,
taskText: description
});
}
});
}
return todos;Key points:
You might also want to check out the Task Manager example in Trilium Demo notes for inspiration on organizing and filtering tasks. To reply, just mention @dosu. How did I do? Good | Irrelevant | Incorrect | Verbose | Hallucination | Report 🐛 | Other |
Beta Was this translation helpful? Give feedback.

@ZangXincz You can extract todo items from Trilium using the backend script API. Todo checkboxes are stored as HTML with a specific structure:
Here's a backend script example to extract all unchecked todos under a root note: