Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Colour Old Events - Google Apps Script

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.

🔗 View Script Project

Features

  • 🎨 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

Quick Start

  1. Copy the Script

    • Go to Google Apps Script
    • Create a new project
    • Replace the default code with the contents of Code.js
  2. Enable Calendar API

    • In Apps Script, click "Services" in the left sidebar
    • Click "+ Add a service"
    • Select "Google Calendar API" and click "Add"
  3. Configure Settings

    • Edit the configuration section at the top of the script
    • Add your calendar IDs to the CALENDAR_IDS array
    • Adjust other settings as needed (see Configuration section below)
  4. 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

Configuration

Calendar IDs

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'

Date Settings

const DATE_OFFSET_DAYS = -1;        // -1 = yesterday and everything earlier
const PROCESSING_RANGE_DAYS = 30;   // Look back 30 days from the cutoff

Event Color

const 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

Event Types

const EVENT_TYPES = ['default']; // Only regular events

Available 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

How It Works

  1. Date Calculation: Determines the cutoff date based on your offset setting
  2. Calendar Processing: Iterates through each configured calendar
  3. Event Retrieval: Fetches events within the specified date range using the Google Calendar API
  4. Filtering: Only processes events that match your criteria (event type, not already colored)
  5. Color Application: Updates event colors using the Calendar API
  6. Progress Logging: Provides detailed console output for monitoring

Example Use Cases

  • 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

Troubleshooting

Common Issues

"No calendar IDs configured" error

  • Make sure you've added at least one calendar ID to the CALENDAR_IDS array

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_DAYS for initial runs

Monitoring

The script provides detailed console logging. To view logs:

  1. Run the script manually from the Apps Script editor
  2. Click "Execution log" to see detailed output
  3. Monitor daily runs through the "Executions" tab

Technical Details

  • API Limits: Includes built-in rate limiting and error handling
  • Pagination: Handles large result sets automatically
  • OAuth Scopes: Requires calendar.events permission
  • Date Format: Uses RFC3339 format for API calls
  • Event Processing: Client-side filtering for event types and colors

Contributing

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

License

This script is provided as-is for educational and personal use. Modify and distribute as needed.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages