メインコンテンツにスキップ

google-calendar-merge

Sync events from multiple Google Calendars to one target calendar.

AI Summary

google-calendar-merge

A Google Apps Script that automatically consolidates events from multiple Google Calendars into a single destination calendar

Target Users

Beginner-to-intermediate GAS users who need to automatically merge personal, work, or team calendars into one shared calendar

Problems Solved

Eliminates the need to manually copy events or check multiple calendars separately, enabling centralized management without duplicates

Tags

Main Features

1
Automatic multi-calendar merge

Scans 30-day events via CalendarApp, checks for existing events, and creates them in the destination calendar to automate synchronization

2
Duplicate prevention

Searches the destination calendar by start/end time; if an event already exists the script skips creation, avoiding duplicates

3
Periodic execution with triggers

By adding a time-based trigger, the script runs regularly to keep the merged calendar up to date

4
Minimal setup

Works by simply specifying calendar IDs; no extra libraries or API keys are required

5
Share free/busy without details

Creates events titled "Busy" so you can share availability while hiding event details

Usage Examples

Sync multiple calendars for the next 30 days

/**
 * Copies events from source calendars to a destination calendar.
 * Prevents duplicates and hides details by naming events "Busy".
 */
function mergeCalendars() {
  const SOURCE_CAL_IDS = [
    'source1@example.com',
    'source2@example.com'
  ];
  const DEST_CAL_ID = 'destination@example.com';

  const destCal = CalendarApp.getCalendarById(DEST_CAL_ID);
  const today = new Date();
  const until = new Date();
  until.setDate(today.getDate() + 30);

  SOURCE_CAL_IDS.forEach(id => {
    const srcCal = CalendarApp.getCalendarById(id);
    const events = srcCal.getEvents(today, until);

    events.forEach(event => {
      const exists = destCal
        .getEvents(event.getStartTime(), event.getEndTime())
        .some(e => e.getStartTime().getTime() === event.getStartTime().getTime());

      if (!exists) {
        destCal.createEvent('Busy', event.getStartTime(), event.getEndTime(), {
          description: `Synced from ${id}`
        });
      }
    });
  });
}

Copy the function, replace IDs with your own, run mergeCalendars, and add a time-based trigger to keep calendars in sync automatically.