Create action for Todoist with title as due date

Can anyone help me on this one? I usually wake up in the morning with 15 things in my head I need to do today that I want to get into Todoist. I think the easiest way for me would be to quickly write a draft that looks like this:

Follow up on change in insurance
Deposit check at the bank
Check on car repair
Reach out to Paul about catering

What I’d like is for Drafts to take the title “Today” and append that to every line as it processes them in Todoist Quick Add syntax. I’m sure this is easy but my scripting ability is nil.

Any suggestions would be much appreciated.

Start with this Tasks in Todoist action.

Make this modification:

// look for the line below - it's at the top of the script
let lines = draft.content.split("\n");

// add this line after it...
lines = => `${ln} today`);

That should do it. That new line iterates over the array of lines, and updates it to append " today" at the end of each.

Thanks a lot. I’ll give it a try. However, if I understand this, it will always append “today” to each task as opposed to grabbing “today” from the draft title. It would be great it I could put the title as “tomorrow” and have drafts append that string accordingly. Is there a way to do that?

Maybe replace …

let lines = draft.content.split("\n");

… with …

let lines = => strLine + " " + draft.title).slice(1);

Thank you. What happens with this line?
lines = => ${ln} today);

That line isn’t in the original action.

My suggestion is similar to, but not the same as Greg’s. Both start from the same point.

I suggested a replacement line of code to, whereas Greg suggested an additional line of code.

If you want to try my suggestion, either take that line out, or start from the original action.

1 Like

Exactly what I needed to understand. Thank you.

That works perfectly. So now can I take advantage of your kindness and ask you if there’s a simple way of expanding this functionality? So, for instance, if my list looked like this…

Buy milk
Pick up dry cleaning
Wash car

Order socks
Call Mark
Learn how to code javascript

Return soccer ball
Cancel subscription
Seriously learn how to code!

…Todoist could parse it and add the dates to the relevant items? I suppose the dates would have to include some signifier before it ("!" “#” “$” whatever) to flag them because they’d no longer just be in the title. Is it doable? I totally understand if you don’t feel like writing it all out or explaining it to me. Perhaps you could point me to a similar action and I can try to decipher and transpose it. I appreciate any advice you could offer. Thanks.

its always helpful to breakdown the action you want to build into smaller chunks.
Or ask yoursefl whats different now compared to the previous input.

In your example you inserted new due dates so obivously you can’t use @sylumer’s example code to be successfull. But this code snippets allow you (more or less) to get the first line in a chunk and use it as due dates for all other ones in that chunk.
So first you have to split your example into those smaller chunks for each due dat.
If you’re stickng with that scheme you always have two “newline characters” before each new due date.
To achieve this you can use the following snippet:

let chunks = draft.content.split("\n\n")

Now the chunks variable contains an array of text similar to your first example with only one due date. You have to repeat the same steps for each due date in that array.
Therefore you’ll need a for-loop:

for(chunk of chunks){
  // now chunk contains the text block for this due date

in the for loop you should do something similar to the snippet from sylumer but you can’t use the “draft.title” anymore - instead the first line of each “chunk” is the due date for the following lines.

If you break this down further you may come to a similar solution which I tested:

// tasks with headers as due dates

// split content by two newline
let chunks = draft.content.split("\n\n");

let tasks = [];

for(chunk of chunks){
  // split chunk by new line
  let lines = chunk.split("\n");
  // due date of the current chunk is the first line (index zero)
  let curDueDate = lines[0];
  // remove first element in lines array
  lines = lines.slice(1)
  // repeat for each element in lines
  for(line of lines){
      // add line together with the date to the tasks array
      tasks.push(line + " " + curDueDate);

// now from the draft are stored with their due date in the taks array
// we just need to add them to todoist now.
let todoist = Todoist.create()
// repeat with each element of the tasks array
for(task of tasks){

this script worked for me with the following demo content (i noticed you had 3/38 in your example i guess a typo) - you can test with different time formats but the “quickAdd()” function should use todoists natural language parser so anything that works in the add task interface in todoist should work, too.

buy milk
wash car

order socks
call mark

return ball
cancel subscription

Wow. This is exactly what I was looking for. Thank you so much. And I really appreciate you stepping it out for me. My problem isn’t so much conceptualizing how I would go about executing the steps, it’s more that I have no idea what my options are in javascript, Drafts and Todoist and how to execute them. My programming ability stopped at BASIC and PASCAL.

You should offer this action up in the Action Directory. I think I’m not the only one who would appreciate it.

As always, your Todoist solutions are ace. :+1:

1 Like