Multi-outline scripting – a couple of questions


#1

This newly public API seems very promising – more than I had hoped for :slight_smile:

Outline.getOutlines() returns list of all open outlines.

outline.getPath() return the file path associated with outline.

A couple of questions about best practice:

  1. Moving items from one outline to another ? Am I right in thinking that we should create fresh copies of the items in the first outline by stringifying and then destringifying them with serialize and deserialize ? (I notice that there’s an assert which checks that children are in the same outline as their parents, so trying a direct inter-outline move is presumably not the right route).

  2. Timing ? If a script has to open a second .taskpaper file, rather than finding an already open document, I guess it will need to make sure that outline building is complete before moving on to reading and mutation of the second outline. Do you have any thoughts or advice on how one might sensibly do that ?

Rob


#2

You are correct, you can’t take an item from one outline and insert it into another directly. Instead you can export import as you suggest, or easiest is to use outline.importItem.

Ideally I’ll add some sort of API for that in the future. So you can just open the other file directly from the JavaScriptContext. Until then you’ll have to jump back out to the Script Editor context to do the file open… but I don’t “think” timing should ever be an issue. I’m pretty sure all these operations are performed on the single UI thread.


#3

Thanks ! I had overlooked that – much simpler