Colour code Google calendar events automatically using Google Apps Script

Sometimes you want to have a certain colour for the Google Calendar events. I know that you can do it manually, but what if you want it to be colour coded automatically based on some filters. In my case it was based on meeting organizer (my wife to be precise 🙂 ). So decided to try and colour code Google calendar events automatically using Google Apps Script.

Creating the Google Apps script

Go to G-Suite Developers Hub
Start a new Project

In the new Project create a new Script file (let’s call it
Now lets paste the below code

That’s it you are almost ready to try running the script. When you will run it for the first time Goggle will ask you for some permissions.

Go to View > Log to see the output of the script. Here is an example

And the colour of the events (organized by my wife) in the calendar changed from the boring default colour

Google Calendar before update

To a nice basil one.

Google Calendar after update by Google Apps Script

Adding Triggers

Well, we successfully ran it once, but how will it continuously / periodically run. That’s what Triggers are for.

You can access it in 2 ways

  • While you are in the project page click the little clock button (Current project’s triggers)
  • In the main G-Suite Developers Hub page click the … for you project and the Triggers.

Since I wanted my Google Apps script to run every time the calendar is been updated, here is my trigger condition

Google Apps Script Trigger Condition Screenshot

That’s it. Now every time my calendar is updated the Goole Apps script runs and updates the colour of events that were organized by someone (very special in my case :-)).


You don’t have to have G-Suite to have the Google App Script functionality. On the other hand if you do want to sign-up to G-Suite ping me on twitter @IlyaReshet to get 20% off your first year of G Suite Basic or G Suite Business

4 thoughts on “Colour code Google calendar events automatically using Google Apps Script”

    1. Hi Alex,
      Looks like some character encoding creeped in when copy/pasted to the blog

      please replace these 2 lines
      if (events.length > 0) {
      for (i = 0; i < events.length; i++) {
      with these
      if (events.length > 0) {
      for (i = 0; i < events.length; i++) { or just copy the whole snipped agin, I've updated it. Thank you for your feedback .

  1. Hey, Im trying to create a script that changes the color automatically based on the Even Title.
    if the title contains the word “ORANGE” then i want to change the color of the even to “TANGERINE” (dont think they actually have orange)
    And if i get another event, with title RED, then i would want to change the color to RED

    The below code doesn’t seem to be working.

    function ColorEvents() {

    var today = new Date();
    var nextweek = new Date();
    nextweek.setDate(nextweek.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 events = calendar.getEvents(today, nextweek);
    for (var j=0; j<events.length; j++) {
    var e = events[j];
    var title = e.getTitle();
    if (title[0] == "[") {
    if (title == "orange") {
    if (title[0] == '#') {

    1. Hi David,
      I haven’t dived into the details of your code, but in the beginning you are mentioning “if the title contains the word..” while later in the code you are comparing if the title equals.
      See if that might be the issue also try to add Logger statements

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.