Updated Drafts script to process meetings

I had previously shared with you the Drafts script that I use to process my meeting notes. Since the last time I shared it, the Todoist API changed, so I have updated the code to work now (2023). Please find the code below.

// Process Meeting Notes

// Function for removing ("Cacl" and "TTodoist:")
function taskrep(s) {
  var f       = ('Ccal: '||'TTodoist: ')
    , r       = ''
    , re      = new RegExp(f, 'g')
    , matches = s.match(re);
  if (matches) {
    return s.replace(re,r);
  }
}

function taskrep2(s) {
  var f       = ('Ccal: '||'TTodoist: ')
    , r       = ''
    , re      = new RegExp('TTodoist: ', 'g')
    , matches = s.match(re);
  if (matches) {
    return s.replace(re,r);
  }
}

// Scan for ("TThings:" || "TTodoist:")
var d = draft.content;
var lines = d.split("\n");
var n = '';

for (var line of lines) {
 if (line.includes("Ccal:")) {
  line = taskrep(line);
  const baseURL = "fantastical2://x-callback-url/parse/"; 
  var cb = CallbackURL.create();
  cb.baseURL = baseURL;
  cb.addParameter("sentence", line);
  cb.addParameter("add",1);
  // open and wait for result
  var success = cb.open();
  if (success) {
   console.log("Event created");
  }else{
     console.log("error!");
  }
  n += line + "\n";
 } else if (line.includes("TTodoist:")) {
  var x=line;
    //this is the line that contains the text of the task
  line = taskrep2(line);
    
    //add a todoist variable
    var todoist = Todoist.create();

  //let the task content be equat to the line we will add
  let taskContent = line;

  //this is where we add the line and wait for the response 
  let createTaskResponse = todoist.createTask({
     "content": taskContent,
  })

  //handle error codes by printing appropriate message, do the same for success 
  if (!createTaskResponse) {
     let message = "Failed to add task to todoist: " + todoist.lastError;
      console.log(message)
     context.fail(message);
     app.displayErrorMessage(message);
   } else {
      let message = "successfully added task in todoist";
      console.log(message)
      // return relevant parameters of the
   }

  if (!todoist.lastError) {
     app.displaySuccessMessage("successfully added task :)");
  }
 
  n += line + "\n";
 }
 else {
  n += line + "\n";
 }
}
draft.content = n;
draft.update();
Sherif Fadel Fahmy

You get what you see.

Recent Posts

Exploring the Different Mount Systems for Nikkor Lenses

Nikon, one of the leading brands in the photography world, offers a plethora of lenses…

8 months ago

Best Camera Lens Companies: Capturing Moments in Perfection

Capturing perfect moments requires the perfect camera lens. Whether you're a professional photographer or an…

8 months ago

What is the Difference Between Nikkor FX and DX Lenses

In the world of digital photography, Nikon is a brand that has consistently stood out…

8 months ago

A Comprehensive Review: Best Camera Lenses for Every Type of Photographer

For photographers, the right camera lens can make a world of difference. Whether you're a…

8 months ago

Using Node.js for grades website

As I tell my students very often, there is no Goldilocks solution. I have previously…

8 months ago

Unraveling the Difference: Front-End JavaScript vs Node.js

In the realm of web development, two terms that frequently arise are front-end JavaScript and…

9 months ago