Created
January 20, 2025 20:23
-
-
Save BrandenBedoya/455717824632fad7511f0e7a20d6dd82 to your computer and use it in GitHub Desktop.
Google Calendar - Auto Color Coding - Apps Script
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
// Define keywords and their corresponding colors in order of priority | |
var keywords = [ | |
//Mandatory Events | |
{ keyword: 'DR.', color: CalendarApp.EventColor.RED }, | |
{ keyword: 'DOCTOR', color: CalendarApp.EventColor.RED }, | |
{ keyword: 'FLY', color: CalendarApp.EventColor.RED }, | |
{ keyword: 'FLIGHT', color: CalendarApp.EventColor.RED }, | |
//Work Events | |
{ keyword: 'WORK', color: CalendarApp.EventColor.YELLOW }, | |
{ keyword: 'UPWORK', color: CalendarApp.EventColor.YELLOW }, | |
//Gym and Self Care Events | |
{ keyword: 'GYM', color: CalendarApp.EventColor.PALE_BLUE }, | |
{ keyword: 'EOS', color: CalendarApp.EventColor.PALE_BLUE }, | |
{ keyword: 'MUAY THAI', color: CalendarApp.EventColor.PALE_BLUE }, | |
{ keyword: 'JIU JITSU', color: CalendarApp.EventColor.PALE_BLUE }, | |
{ keyword: 'BOXING', color: CalendarApp.EventColor.PALE_BLUE }, | |
{ keyword: 'WORKOUT', color: CalendarApp.EventColor.PALE_BLUE }, | |
{ keyword: 'JOURNAL', color: CalendarApp.EventColor.PALE_BLUE }, | |
{ keyword: 'THERAPY', color: CalendarApp.EventColor.PALE_BLUE }, | |
{ keyword: 'MEDITATION', color: CalendarApp.EventColor.PALE_BLUE }, | |
{ keyword: 'NAP', color: CalendarApp.EventColor.PALE_BLUE }, | |
{ keyword: 'MEDITATE', color: CalendarApp.EventColor.PALE_BLUE }, | |
//Dates | |
{ keyword: 'DATE', color: CalendarApp.EventColor.PALE_RED }, | |
{ keyword: 'GIRL', color: CalendarApp.EventColor.PALE_RED }, | |
{ keyword: 'MOVIES', color: CalendarApp.EventColor.PALE_RED }, | |
{ keyword: 'SHOPPING', color: CalendarApp.EventColor.PALE_RED }, | |
//Reminders | |
{ keyword: 'BDAY', color: CalendarApp.EventColor.GRAY }, | |
{ keyword: 'BIRTHDAY', color: CalendarApp.EventColor.GRAY }, | |
{ keyword: 'SUBSCRIPTION', color: CalendarApp.EventColor.GRAY }, | |
{ keyword: 'CANCEL', color: CalendarApp.EventColor.GRAY }, | |
{ keyword: 'MONTHLY', color: CalendarApp.EventColor.GRAY }, | |
{ keyword: 'ANNUAL', color: CalendarApp.EventColor.GRAY }, | |
//Optional Events | |
{ keyword: '?', color: CalendarApp.EventColor.PALE_GREEN } | |
]; | |
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().toUpperCase(); | |
for (var k = 0; k < keywords.length; k++) { | |
if (title.includes(keywords[k].keyword)) { | |
e.setColor(keywords[k].color); | |
break; // Stop checking after the first match | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is my code to auto color code my Google Calendar events after creating one on my phone/computer. One less step needed when creating future calendar events
Steps to implement code:
And done! Have fun organizing your life :)