0

I'm trying to develop a method for adding Google Tasks to my running task list named todo.txt and is housed in Google Drive. I've found a way to grab the tasks. Of course, the data will nee to be manipulated as well (e.g., concatenate date formats to conform to todo.txt rules) but I'll deal with that next.

The question I have is how to insert them to the top of the todo.txt without overwriting the existing text contained within it. I have read in other circumstances, that I may need to read the current text out, add the new info and then write the whole thing back as an overwrite. Is this necessary? And, if so, how do I do it?

Below is the code I've written thus far, substituting logger.log for the destination file since I don't know how to do it. I;m not a programmer, so polease forgive any ignorance here. Thanks.

function listTasks(taskListId) {
  var taskListId = '12345'; //this is the ID of my Google Tasks (the source data) 
  var name2="Text Journals";  //this is the folder in which my todo.text resides  
  var name="todo.txt";  //this is the name of my todo file (the destination)

  var dir = DriveApp.getFoldersByName(name2).next()
  var tasks = Tasks.Tasks.list(taskListId);
  if (tasks.items) {
    for (var i = 0; i < tasks.items.length; i++) {
      var task = tasks.items[i];
      Logger.log('Task with title "%s" and dute: "%s" and notes "%s" and status "%s" was found.',
                 task.title, task.due, task.notes, task.status);
    }
  } else {
    Logger.log('No tasks found.');
  }
}
Drew
  • 19
  • 2
  • I think insertParagraph is for gDocs rather than text files. – Drew Jan 17 '18 at 00:46
  • One way to do it would be to use a Google Document to store the task info, and then export it to plain text after grabbing your latest tasks. When your to-do document is a Google doc, you can access its structure and insert paragraphs as desired. – tehhowch May 02 '18 at 13:16

0 Answers0