Advanced Productivity I. Add some color to your Calendar
Sep 19, 2023
Is your calendar also an unreadable mess of overlapping events?
Get some clarity with this simple script.
Introduction
I typically have 4 sorts of events in my calendar. And have always struggled when looking at my week overview. AEs will ping me last minute to let me know I own a call I’m not supposed to be on, I’ll get too many 1:1 booked all together, leaving no time for important business, and I’ll miss out on preparing important customer calls. Well, after a month trying this out I can confidently say I’m now more in control of my calendar. Meetings I should watch (Zoom meetings I shouldn’t be on!) are flagged in bright red. External calls with customers show up in yellow, a yellowy day means lot’s of prep ahead. Internal meetings in green show me if my time being abused, or I’m too isolated from my team. And grays will tell me blocked time that shouldn’t be overbooked.
I hope this helps! Find the code and instructions below. Share if you dare and follow me for more unsolicited productivity advise.
PS: The code is dead simple, so having coding experience to edit this shouldn’t be a must. But you can DM me and I’m more than happy to help.
Instructions
Instructions:
- Open https://script.google.com/
- Create a new project, and give it a meaningful name (Calendar Color Events)
- Paste the code below in the Code.gs file
- Open the triggers menu on the right hand side
- Add a trigger that executes the function every time the calendar is updated
const COLOR_CODE = {
external: CalendarApp.EventColor.YELLOW,
internal: CalendarApp.EventColor.GREEN,
block: CalendarApp.EventColor.GRAY,
warning: CalendarApp.EventColor.RED,
};
const COMPANY_DOMAIN = "@mycompany.com";
const MY_USERNAME = "myusername";
function ColorEvents() {
var today = new Date();
var nextmonth = new Date();
nextmonth.setDate(nextmonth.getDate() + 31);
Logger.log(today + " " + nextmonth);
var calendars = CalendarApp.getCalendarsByName(
`${MY_USERNAME}${COMPANY_DOMAIN}`
);
Logger.log("found number of calendars: " + calendars.length);
calendars.forEach((calendar) => Logger.log(calendar.getName()));
for (var i = 0; i < calendars.length; i++) {
var calendar = calendars[i];
var events = calendar.getEvents(today, nextmonth);
for (var j = 0; j < events.length; j++) {
var e = events[j];
var title = e.getTitle();
var description = e.getDescription();
//
// YELLOW for calls with external people unless I'm the owner
// RED if it's external, and I'm the owner
//
if (
e
.getGuestList()
.map((guest) => guest.getEmail())
.some((email) => !email.match(COMPANY_DOMAIN))
) {
if (!!e.getDescription().match(/zoom.us/) && e.isOwnedByMe()) {
Logger.log(`Found a ZOOM event you own: ${e.getTitle()}`);
e.setColor(COLOR_CODE.warning);
} else {
Logger.log(`Found an EXTERNAL meeting: ${e.getTitle()}`);
e.setColor(COLOR_CODE.external);
}
} else if (
title.includes("Sync") ||
(isAllGuestsFromMyCompany(e.getGuestList(true)) &&
e.getGuestList(true).length > 1)
) {
//
// GREEN for internal meetings
//
Logger.log(`Found an INTERNAL meeting: ${e.getTitle()}`);
e.setColor(COLOR_CODE.internal);
} else if (e.getGuestList(true).length < 2) {
//
// GRAY for personal events that block my calendar
//
Logger.log(`Found an BLOCK event: ${e.getTitle()}`);
e.setColor(COLOR_CODE.block);
}
}
}
}
function isAllGuestsFromMyCompany(guestList) {
return guestList
.map((guest) => guest.getEmail())
.every((email) => email.match(COMPANY_DOMAIN));
}