Skip to content

Instantly share code, notes, and snippets.

@samuelbeek
Created May 27, 2024 08:33
Show Gist options
  • Save samuelbeek/e89403892caecb5e3da7ee61addd0653 to your computer and use it in GitHub Desktop.
Save samuelbeek/e89403892caecb5e3da7ee61addd0653 to your computer and use it in GitHub Desktop.
Calendar Colors

How to use this script

  1. Copy the below code
  2. Go to Google App Script
  3. Click "New Project"
  4. Name it Calendar Colors
  5. Paste the code from Code.gs in the file with the same name
  6. Click run if it's working appropriately
  7. Go to Triggers and set it to trigger every hour
function ColorEvents() {
var today = new Date();
var nextweek = new Date();
nextweek.setDate(nextweek.getDate() + 14);
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().toLowerCase();
var desc = e.getDescription().toLowerCase();
// make 1-1s indigo
if ((title.includes("x") || title.includes("/") || title.includes("1-1") || title.includes("<>"))
&& !(title.includes("company") || title.includes("sync") || title.includes("veed") )) {
e.setColor('9'); // '9' corresponds to Indigo
}
// make to do tasks starting with [] green
if (title[0] == "[") {
e.setColor(CalendarApp.EventColor.GREEN);
}
// make tasks starting with ! red
if (title[0] == "!") {
e.setColor(CalendarApp.EventColor.RED);
}
// make breaks starting with # orange
if (title[0] == '#') {
e.setColor(CalendarApp.EventColor.ORANGE);
}
// make interviews pale green
if(desc.indexOf("candidate")>-1) {
e.setColor(CalendarApp.EventColor.PALE_GREEN);
}
// make user interview sections purple
if(desc.indexOf("user interviews")>-1) {
e.setColor(CalendarApp.EventColor.MAUVE);
}
// make calendly invites yellow
if(desc.indexOf("calendly")>-1) {
e.setColor(CalendarApp.EventColor.YELLOW);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment