Google Calendar AutomationDifficulty: Intermediate⚡ Weekly Trigger

Detect Google Calendar Scheduling Conflicts & Log to Sheets

Scans upcoming weekly schedule, detects overlapping calendar appointments, and flags double-booked time slots in a spreadsheet table for quick resolution.

Required OAuth Scopes: https://www.googleapis.com/auth/calendar.readonly • https://www.googleapis.com/auth/spreadsheets
Code.gs (Apps Script V8 Runtime)
function findCalendarConflicts() {
  const calendar = CalendarApp.getDefaultCalendar();
  const now = new Date();
  const nextWeek = new Date(now.getTime() + 7 * 24 * 60 * 60 * 1000);
  const events = calendar.getEvents(now, nextWeek);
  
  const sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Conflicts');
  const rows = [['Event 1', 'Event 2', 'Overlap Start', 'Overlap End']];
  
  for (let i = 0; i < events.length; i++) {
    for (let j = i + 1; j < events.length; j++) {
      const e1 = events[i];
      const e2 = events[j];
      
      if (e1.getStartTime() < e2.getEndTime() && e2.getStartTime() < e1.getEndTime()) {
        rows.push([e1.getTitle(), e2.getTitle(), e1.getStartTime().toString(), e1.getEndTime().toString()]);
      }
    }
  }
  
  sheet.clearContents();
  sheet.getRange(1, 1, rows.length, 4).setValues(rows);
}

Line-by-Line Code Explanation

Line 4-5: Queries all events scheduled across the next 7 days.
Line 10-18: Performs O(n^2) interval intersection comparison to detect double-bookings.
Line 20-21: Records overlapping appointment titles and times into a review tab.

Step-by-Step Setup & Deployment

  1. Create a sheet tab named "Conflicts".
  2. Run the function to audit double-bookings.

Best Practices for Quota & Rate Limit Management

When deploying this automation in Google Workspace, adhere to these operational principles:

  • Batch Reads & Writes: Never execute getValue() or setValue() inside loops. Read ranges into memory in 1 call, process arrays in V8 memory, and commit changes with a single setValues() call.
  • Execution Timeouts: Apps Script terminates scripts exceeding 6 minutes. For multi-thousand row datasets, implement batch pagination with resume timestamps stored in PropertiesService.
  • OAuth Permissions: Scope your manifest (appsscript.json) narrowly to prevent security prompts from alarming external team members.

Frequently Asked Questions

Is Google Apps Script completely free to use?

Yes. Google Apps Script is built into all free Google accounts and Google Workspace editions. There are no server fees or subscription costs for running scripts within daily quotas.

Can I run this script on an automated schedule without keeping my computer on?

Yes. Time-driven triggers execute on Google's cloud infrastructure. Your script will run reliably even when your computer is closed or offline.

More Google Calendar Automation Snippets