Colorful Google Calendar

I find it useful to color-code my calendar.  In my case anything starting with a bracket [ ] is about work. It may be [c] for communications, [cl] for some client, etc.  I also have entries starting with # for personal things (family, learning, etc).  And finally, those with ! are things I tend to postpone or forget (exercise, stretching, etc).

I found a little google script that I adapted to do this automatically.  The script essentially says:

  • If an entry on the calendar starts with [ give it a certain colour
  • If it starts with # some other colour
  • If it starts with ! another colour.

If you want to use it yourself, go to https://script.google.com/, and create a new project.  You should see something like this:

Rename the "Untitled project" to something like "Google Calendar Auto-Color".  Instead of function myFunction() {} we are going to write our own function.  Copy paste the following:

function ColorEvents() {

  var today = new Date();
  var nextweek = new Date();
  nextweek.setDate(nextweek.getDate() + 7);

  var calendars = CalendarApp.getAllOwnedCalendars();

  for (var i=0; i<calendars.length; i++) {
    var calendar = calendars[i];
    var events = calendar.getEvents(today, nextweek);
    for (var j=0; j<events.length; j++) {
      var e = events[j];
      var title = e.getTitle();
      if (title[0] == "[") { // work related
        // other colours: https://developers.google.com/apps-script/reference/calendar/event-color
        e.setColor(CalendarApp.EventColor.PALE_BLUE);
      }
      if (title[0] == "!") { // fitness & health
        e.setColor(CalendarApp.EventColor.YELLOW);
      }
      if (title[0] == '#') { // Family & free time events
        e.setColor(CalendarApp.EventColor.PALE_GREEN);
      }
    }
  }
}

What does it do?

It checks what day is today, and opens your calendars (associated to the google account that has created the script).  It then gets all events between today and next week.  The key section happens in these three lines:

if (title[0] == "[") { // work related
        e.setColor(CalendarApp.EventColor.PALE_BLUE);
      }
if (title[0] == "!") { // fitness & health
        e.setColor(CalendarApp.EventColor.YELLOW);
      }
if (title[0] == '#') { // Family & free time events
        e.setColor(CalendarApp.EventColor.PALE_GREEN);
      }

You can of course, change it. For example, if your calendar item starts with "f:" that may be how you label items for family.  Edit it according to your needs, and check https://developers.google.com/apps-script/reference/calendar/event-color for your favorite colours.  Then save it.  When ready, go to the left and select "Triggers":

You can, for example, make it run every hour with the following settings:

You are good to go.  Go back to your editor and click "> Run" to see if it worked.  (You may need to approve the script from your google account).  You don't need to hit "Deploy" (that is for running an app for others).

Enjoy!