A Google Apps Script that automatically colours calendar events that occurred before a specified date. Perfect for visually organizing your calendar by dimming old events with a consistent color.
- 🎨 Automatic Event Coloring - Colors events older than your specified cutoff date
- 📅 Multiple Calendar Support - Process events across multiple calendars
- ⚙️ Flexible Configuration - Customizable date ranges and event types
- 🔄 Daily Automation - Set up triggers to run automatically
- 🎯 Event Type Filtering - Choose which types of events to color
- 🚀 Efficient Processing - Handles large numbers of events with pagination
-
Copy the Script
- Go to Google Apps Script
- Create a new project
- Replace the default code with the contents of
Code.js
-
Enable Calendar API
- In Apps Script, click "Services" in the left sidebar
- Click "+ Add a service"
- Select "Google Calendar API" and click "Add"
-
Configure Settings
- Edit the configuration section at the top of the script
- Add your calendar IDs to the
CALENDAR_IDSarray - Adjust other settings as needed (see Configuration section below)
-
Set Up Automation
- Click "Triggers" in the left sidebar
- Click "+ Add Trigger"
- Choose function:
ColorOldEvents - Event source: Time-driven
- Type: Day timer
- Time of day: Choose your preferred time
const CALENDAR_IDS = [
'primary', // Your main calendar
'example@group.calendar.google.com', // Shared calendar
'another@group.calendar.google.com' // Another calendar
];How to find Calendar IDs:
- Go to Google Calendar settings
- Click on the calendar you want to include
- Scroll down to "Calendar ID"
- For your primary calendar, use
'primary'
const DATE_OFFSET_DAYS = -1; // -1 = yesterday and everything earlier
const PROCESSING_RANGE_DAYS = 30; // Look back 30 days from the cutoffconst EVENT_COLOR = '8'; // Graphite (grey)Available Colors:
'0': Default'1': Lavender'2': Sage'3': Grape'4': Flamingo'5': Banana'6': Tangerine'7': Peacock'8': Graphite (recommended for old events)'9': Blueberry'10': Basil'11': Tomato
const EVENT_TYPES = ['default']; // Only regular eventsAvailable Event Types:
'default': Regular events'birthday': Special all-day events with annual recurrence'focusTime': Focus time events'fromGmail': Events from Gmail'outOfOffice': Out of office events'workingLocation': Working location events
- Date Calculation: Determines the cutoff date based on your offset setting
- Calendar Processing: Iterates through each configured calendar
- Event Retrieval: Fetches events within the specified date range using the Google Calendar API
- Filtering: Only processes events that match your criteria (event type, not already colored)
- Color Application: Updates event colors using the Calendar API
- Progress Logging: Provides detailed console output for monitoring
- Archive Old Events: Color all events older than yesterday with grey
- Seasonal Organization: Color events from last month with a specific color
- Event Type Management: Only color regular events, ignore birthdays
- Multiple Calendar Sync: Keep consistent coloring across work and personal calendars
"No calendar IDs configured" error
- Make sure you've added at least one calendar ID to the
CALENDAR_IDSarray
Permission errors
- Ensure the Google Calendar API is enabled in your Apps Script project
- Check that you have edit permissions for the calendars you're trying to modify
Script timeout
- For large numbers of events, the script includes delays to respect API limits
- Consider reducing the
PROCESSING_RANGE_DAYSfor initial runs
The script provides detailed console logging. To view logs:
- Run the script manually from the Apps Script editor
- Click "Execution log" to see detailed output
- Monitor daily runs through the "Executions" tab
- API Limits: Includes built-in rate limiting and error handling
- Pagination: Handles large result sets automatically
- OAuth Scopes: Requires
calendar.eventspermission - Date Format: Uses RFC3339 format for API calls
- Event Processing: Client-side filtering for event types and colors
This is a standalone script designed to be copied and customized. Feel free to:
- Modify the configuration for your needs
- Add additional filtering logic
- Extend the color selection options
- Add more comprehensive error handling
This script is provided as-is for educational and personal use. Modify and distribute as needed.