Script to collapse all notes in a document

Hi all,

I’m new to TaskPaper, but I’m loving it so far.

I like to create notes under a task with information like URL’s or links to relevant files on my Mac, but when I have multiple notes entries expanded, it makes my whole document look cluttered and it’s hard to get a quick sense of what’s on my list.

Perhaps there’s a built-in way to do this, but as a software engineer, every problem looks like it needs a program to solve it. :grinning:

So here’s a very short TaskPaper script that will collapse all notes that are children of tasks:

function collapseAllNotes(editor, options) {
  'use strict';

  // only collapse a note if it's a child of a task (we don't want to collapse any projects)
  const allParentsOfNotes = editor.outline.evaluateItemPath("@type=note/parent::@type=task")
  editor.setCollapsed(allParentsOfNotes)

  return true;
}

Application("TaskPaper").documents[0].evaluate({
	script: collapseAllNotes.toString()
});
5 Likes

Nicely done!

Added to wiki

Hi batkins,
I tried you script with a very simple TP file but it doesn’t work… where am I wrong?
what should I show you?

Hi @amelchi

Can you give me some more information? What specifically doesn’t work?

Can you provide an example TaskPaper document?

thanks
it works but it depends on how are “formatted” the notes… if the note starts from Taskpaper menu (item-New Note) it works fine whereas if the note is simply everything that is “not a project, not a task”, sometimes it doesn’t work…
I think the note “free-format” should be better defined…
Thanks again