Shortcut to Fold/Unfold all items in a document (TP3)

I am sure I must have overlooked this. But I searched high and low. Does it exist?

It is not there, but I remember reading somewhere that it was in the roadmap ( Is that true @jessegrosjean?) If you are good at applescript, I believe you might be able to get it done with it (Sorry, I am cannot figure it out myself). There are a couple of Script masters here. @complexpoint might be able to help if you ask very nicely :slight_smile:

Thanks @Victor. My abilities with AppleScript are quite limited, but I am not a complete beginner. Time is more of an issue. Perhaps Iā€™ll just wait for @jessegrosjean to get around to it, if it is in the roadmap.

You can do this, I think, with āŒ˜A āŒ˜.
or, more directly, with āŒ˜ āŒ„ . Fold Items Completely

(Both toggle between full expansion and full fold)

See under Help > Search > Fold

Does that match what you are after ?

1 Like

Hi Thanks @complexpoint. What I am looking for is a way to toggle unfolding/enfolding all the projects on a page at once, so I see only the projects with their dots. This command only seems to do unfold/enfold the selected project?.

Note you can do this by doing Select All and then toggling folding.

1 Like

Now why didnā€™t I think of that?
[Hangs head in shame.]
Thanks Jesse.

1 Like

Various approaches come to mind:

  1. Preface the fold shortcut with āŒ˜A to select everything
  2. Use a saved search like //@type=project to get a project headers only view
  3. Use something like Keyboard Maestro to bundle the āŒ˜A and āŒ˜. into a single keystroke

(One could of course write a brief script, but perhaps that might be overkill)

Option 2 may be good if you use subprojects (lines ending in a colon which are nested under other projects)

As in:

@search(//@type=project)
1 Like

Thanks @complexpoint. That search works great. The disadvantage of that being I have to create that list item in all of my different documents. OK thatā€™s no big deal. I should stop whinging and be happy. The more I use TaskPaper the more I like it!

1 Like

create a list item in all of my different documents

Something like a TextExpander or Keyboard Maestro shortcut ?

Yeah I guess. Or maybe @jessegrosjean could be persuaded to include a ā€˜Collapse all projects in documentā€™ menu item/shortcut? :smiley: I mean, it looks pretty!

Iā€™m not sure. One one hand itā€™s of course easy to add. On the other hand if I add all the different expand/collapse enumerations that are possible that view menu starts getting really big. At the moment I just canā€™t decide and so Iā€™m leaving them out until Iā€™m sure I want them in.

Of course it would not make sense to list all the different enumerations in the View menu (or should it be in the Items menu?), but my argument in favour of adding ā€œCollapse Allā€ would be: It is so neat and satisfying to see just a list of all your project items. Suddenly your tasks donā€™t look so complex! :smiley:

I understand thought iā€™m still not sure. In the meantime I think this script will do what you want:

var TaskPaper = Application('TaskPaper')

function TPContext(editor, options) {
  var projects = editor.outline.evaluateItemPath('//@type=project');
  var anyCollapsed = false;
  
  projects.forEach(function (each) {
    if (editor.isCollapsed(each)) {
      anyCollapsed = true;
    }
  });
  
  if (anyCollapsed) {
    editor.setExpanded(projects);
  } else {
    editor.setCollapsed(projects);
  }
}

TaskPaper.documents[0].evaluate({
  script: TPContext.toString()
});
1 Like

You could also see it, I guess, as the question of how to easily make sure that all your working documents contain a particular custom set of saved searches, including something like:

Projects @search(//@type=project)

Cut and paste is probably not a bad approach, but if you wanted, you could also keep the list in a script which took over:

  • Wrapping the paths in @search( ... ) and checking for \) escapes
  • Checking which searches a document already has, and only adding the missing ones.

Maybe something roughly along these lines :

// MAKE SURE THE THE CURRENT TASKPAPER 3 DOCUMENT
// CONTAINS ALL THE ELEMENTS YOUR USUAL MENU
// OF SAVED SEARCHES

(function () {
    
    var dctMenu = {
        'Project list': '//@type=project',
        'Inbox': '//Inbox',
        'Soon': '//@due <=[d] next week +14d',
        'Overdue':'//@due <[d] now'
    }


    function fn(editor, options) {

        var outline = editor.outline,
            root = outline.root,
            strText = outline.toString(),
            dctSearch = options.menu;
            
            // Any search menu items not found in this document ?
            lstMissing = Object.keys(dctSearch).filter(function (k) {
                return strText.indexOf(dctSearch[k]) === -1;
            })
            .map(function (k) {
                return k + ' @search(' + dctSearch[k].replace(/\)/g,
                    '\\)') + ')';
            })
            .sort();

        // Add any missing searches to this document's search menu
        if (lstMissing.length > 0) {
            outline.groupUndoAndChanges(function () {
                root.insertChildrenBefore(
                    ItemSerializer.deserializeItems(
                        lstMissing.join('\n'),
                        outline,
                        ItemSerializer.TEXTMimeType
                    ),
                    root.firstChild
                )
            })
        }
    }

    var ds = Application("TaskPaper")
        .documents;

    return ds.length ? ds[0].evaluate({
        script: fn.toString(),
        withOptions: {
            menu: dctMenu
        }
    }) : undefined;
    
})()

that works perfectly. thanks @jessegrosjean!

Thanks @complexpoint. Scripting genius!! I can see this could easily be tweaked to be useful for a range of different scenarios.

Hard to tell exactly when the Rube Goldberg / Heath Robinson line has been crossed, but it would also be possible to save the saved searches of one document, (e.g. as a small JSON file) and load them into another, or choose a selection of them from a menu.

But perhaps this is what cut and paste is for : - )

I need to know where that line is - and fast. :neutral_face:

1 Like

A TextExpander solution works well here, I think ā€“ two or three chars which are instantly replaced by a group of your preferred searches, when you start a new TaskPaper 3 document, or want to add searches to an existing one.

1 Like