This is a lightweight, reliable Google Apps Script that automatically synchronizes events from external sources (such as iCal schedule links or other Google Calendars) into a single target calendar.
- Universal Sources: Supports both
.ics(iCal) links and direct Google Calendar IDs. - Smart Deduplication: Uses unique tags (
UNIQUE_TAG_KEY) per source to prevent duplicate events in your calendar. - Automatic Cleanup: Events deleted from the source are neatly removed from your target calendar.
- Custom iCal Parser: Includes a robust date parser specifically built to prevent timezone issues (daylight saving time) and 1970 errors.
- Lightweight: Searches 4 days back and 30 days ahead by default to prevent timeouts.
- Go to Google Apps Script and create a new project.
- Copy the code from
sync.gsin this project and paste it into your Apps Script editor. - Adjust the following two variables at the top of the script:
const SOURCE = "YOUR_ICAL_LINK_OR_SOURCE_CALENDAR_ID"; const TARGET_CALENDAR_ID = "YOUR_TARGET_CALENDAR_ID"; // Often your email address
- Save the script and click Run once to grant Google the necessary permissions (CalendarApp & UrlFetchApp).
To run this script in the background:
- Click the clock icon on the left menu (Triggers).
- Add a new trigger.
- Choose the function
syncUniversalToGCal. - Select the event source: Time-driven.
- Select the type of time based trigger, for example Hourly or Daily, depending on how often your schedule changes.
Because this script is built to be light and fast, it currently does not support:
- Complex RRULEs: iCal events with a recurrence rule (e.g., "every Monday") are only scheduled on the first date.
- UTC Z-notations: iCal times ending with a 'Z' (Zulu time/UTC) without a local time offset might cause time discrepancies with certain systems.
- Secured calendars: iCal links requiring a login/password do not work directly via
UrlFetchApp.