Automatically Color Coding Google Calendar
Update: @bigal123 sent me a link to this Coda doc which can do even more than I’m describing below. One caveat: you have to give another party access to your calendar. That is not necessary when you’re using the script below.
Koen Bollen wrote a little script for me to automatically color-code my calendar based on the first character of the event. It is super handy. More people asked me how I do this so this is a short guide how to set it up.
Here’s how you set it up:
- Go to https://script.google.com/home
- Click ‘New script’
- Paste the following script:
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] == "[") {
e.setColor(CalendarApp.EventColor.CYAN);
}
if (title[0] == "!") {
e.setColor(CalendarApp.EventColor.RED);
}
if (title[0] == '#') {
e.setColor(CalendarApp.EventColor.GREEN);
}
}
}
}
- Save the project and give it a nice name
- Click the ‘Play’ button to execute the script. A dialog will open to ask for additional permissions. Allow access to your calendar.
- Click the button with an icon of a pin with a clock in it (Triggers)
- Click ‘Add trigger’
- Select ‘ColorEvents’ in the list of functions to trigger
- Change the type to ‘Minutes’ and have the trigger run every 15 minutes. Save the trigger.
This script now automatically colors events that start with a [
cyan, with a !
red and #
green. Adjusting the character and/or colors in the script should not be too difficult.
Done!