Add tasks as project in 2Do

actions
tasks

#1

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.)


#2

So it turns out that it is actually fairly easy to create a project with sub tasks in 2Do using the “paste” URL scheme:

twodo://x-callback-url/paste?text=[[draft]]&forList=Inbox

This works with nested text in a draft:

Project Title
    task 1
    task 2

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?


#3

Seems it is not possible to create a new draft and automatically trigger a second action. So it would be better to find a way to add all the text that would go to that new draft directly to a URL scheme… Not sure how to do that though…


#4

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:

twodo://x-callback-url/paste?text=[[paste_text]]&forList=Inbox

You could also do it all in script, constructing the full URL in a string, and using a CallbackURL object to open that URL.


#5

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?


#6

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.

Hope that covers what you’re after.


#7

Thanks. Just posting this here as a reference:


#9

Success. Thanks so much for your help!

https://actions.getdrafts.com/a/1Qx