I’ve adapted a few existing actions to create a new one that will scan a Draft for all markdown formatted tasks and then create a new task in my 2Do inbox for each item. This seems to be working well. But what I would like to do now is have the action create a new project in 2Do from the document title and then add each of these items as sub-tasks in that project. So, for instance, if I have a document like this:
# Title
- [ ] Item 1
- [ ] Item 2
I will get a 2Do project named “title” with “item 1” and “item 2” as sub-tasks in that project. I’ve tried a few different ways to do this, but nothing has worked. (Unfortunately my scripting ability is very limited and all I can really do is slightly modify existing scripts, not create new ones from scratch.) Thanks for your help!
(Note that this action should work even if some of the lines in the document are not tasks. The idea is that I could take notes at a meeting, add some tasks, and then have a new 2Do project for items to followup on after that meeting.)
So perhaps the best way to accomplish the initial concept would be to take the title and tasks and create a new draft, then run the URL scheme on that draft? Or is there an easier way?
There are couple of ways to create that URL and open it without the need to create a new draft.
The most straightforward way would be to put the new text you constructed in a custom template tag, then use that tag in a Callback URL action step that follows your script, like:
let s = " ... your constructed text ... ";
draft.setTemplateTag("paste_text", s);
Then for the URL scheme in a step after this script, use:
Currently my script parses each line and sends those it finds directly to 2Do, to modify it in this way I would need to append each found line to “s” (using the example above). How do I append to an existing template tag within the script?
For this scenario, consider using a string variable to keep appending to and then substitute that in for “paste text” when you want to use it.
If it was pre-existing in some other scenarios, you might use processTemplate() to get the initial value to initialise the variable with. You could consistently use processTemplate instead of a separate variable, but I personally think it is typically easier (for maintenance and explanation) to work with variables first and then the templates at the end of the process.