Colors for newbie

128 views
Skip to first unread message

Gabriel Arce

unread,
Aug 20, 2022, 4:16:20 PM8/20/22
to Google Apps Script Community
Hi there
This is my first inroad into google app script and I am not a programmer
I am trying to use this code which I modified from Rick Pastoor website

function ColorEvents() {

  var sevendaysago = new Date()
  var today = new Date();
  var nextweek = new Date();
  nextweek.setDate(nextweek.getDate() + 7);
  sevendaysago.setDate(sevendaysago.getDate() - 7);
  Logger.log(today + " " + nextweek);

  var calendars = CalendarApp.getAllOwnedCalendars();
  Logger.log("found number of calendars: " + calendars.length);

  for (var i=0; i<calendars.length; i++) {
    var calendar = calendars[i];
    var calcolor = calendar.getColor();
    //var calcolor = calendar
    Logger.log("calendar color: " + calcolor);
    var events = calendar.getEvents(today, nextweek);
    for (var j=0; j<events.length; j++) 
      {
        var e = events[j];
        var title = e.getTitle();
        var eventcolor = e.getColor();
        Logger.log("event color: " + eventcolor);
          if (title.search("STR1") != -1) {
            e.setColor(CalendarApp.EventColor.YELLOW);
            Logger.log("STR1 Color Change");
          }
          if (title.search("STR2") != -1) {
            e.setColor(CalendarApp.EventColor.ORANGE);
            Logger.log("STR2 Color Change");
          }
          if (title[0] == '#') {
            e.setColor(CalendarApp.EventColor.GREEN);
          }
      }
  }
}

It works perfect but I am not able to figure out how to do something. I would like to include a logic that compares a particular event color with the "default" event color. This default event color is the one you get if you create an event and don't select intentionally a color. 
I am not able to figure out how to obtain that. 
I thought that below may work
    var calcolor = calendar.getColor();
But that is something else (Hex code that does NOT correspond to the default event color)
Appreciate assistance

Regards,
Gabriel
Reply all
Reply to author
Forward
0 new messages