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 code.gs)
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 :-)).

P.S.

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

2 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 .

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.