2

So let's see if I can explain this correctly.

I use a Google Doc to track my to-do list at work. When I add something that needs immediate attention, I will highlight that bullet point and the description of the task with a bright yellow color. Lesser tasks, get a different color, etc. I break up my tasks into different lists under different headings depending on what type of project it's for (so I have a heading for "Website" then a bulleted list under it for all the tasks I need to do that pertain to updating the website, I have a "Videos" heading and a list beneath with all the tasks I need to do for videos, and so on). Within each section, I then highlight based on priority.

My list is long with many sections and I would love it if it were possible that when I highlight a task in a given section as "top priority" with the bright yellow color, that it would - automatically - be copied and moved to a section at the very top of my doc under a heading of "Priorities" that way I can see all in one place all the high priority tasks I want to accomplish across all my projects without having to scan through each section in my document and potentially missing something.

Is this possible to do? I've heard of Google Apps Script but I've never really dived into it. I have basic coding knowledge and can usually find my way around HTML, Javascript, and so on.

Is something like this possible? And how would I go about it?

Brenda
  • 19
  • 1
  • I've given an answer from a coding perspective, but you'll also need to consider how you will run the code. I would imagine you could tie the script to a "Custom Menu" function as seen here: https://developers.google.com/apps-script/guides/menus – Aleister Tanek Javas Mraz Sep 27 '19 at 15:43
  • 1
    I think you should consider using Spreadsheets instead, it can make managing the data how you want a lot easier, and using Apps Scripts with it works well. Doing it from a Doc would be complicated because if you have a paragraph and one sentence is one color and another sentence is a different color, it can make matter complicated, on a sheet you can organize the lists and manage the highlights easily. Is this an acceptable approach? – AMolina Sep 30 '19 at 07:42

1 Answers1

0

Brenda.

You'll probably start with this:

var doc = DocumentApp.getActiveDocument();
var body = doc.getBody();
var lists = body.getListItems();

var childIndex = 0;
for (var i = 0; i < doc.getNumChildren(); i++) {
    var child = doc.getChild(i);
    if (child.getType() == DocumentApp.ElementType.LIST_ITEM){
      while(child.getType() == DocumentApp.ElementType.LIST_ITEM){
        child = doc.getChild(i)
        childIndex = body.getChildIndex(child);
        Logger.log(childIndex)
        i++
      }
      child = doc.getChild(i-2)
      var listId = child.getListId();
      Logger.log(childIndex)

      // You'll want to do something like...
      // if child.getBackgroundColor() == "Yellow"...

        // Here you can add an element to your "Priorities" list as well:
        // var newElement = child.getParent().insertListItem(childIndex, elementContent);
        // newElement.setListId(child);
      break;
    }
}

Here's a good reference: https://stackoverflow.com/a/20729760/5415398

And another: https://stackoverflow.com/a/26419644/5415398

Here you are getting the document, its body, and any lists contained therein. You can either use the "lists" variable directly, or you can instead loop through all of the document's children and for any that are LIST_ITEMs, they can be processed as needed.

You'll try to capture the highlighting of the list item with the ".getBackgroundColor()" function, and if it meets your conditions, then add the item to your priorities list.

(Note: This answer can and should be improved to be complete.)