Skip to content

Instantly share code, notes, and snippets.

@jasonmadigan
Last active November 2, 2017 09:17
Show Gist options
  • Save jasonmadigan/e48c23a773ff76e6d47d1d13b4c69713 to your computer and use it in GitHub Desktop.
Save jasonmadigan/e48c23a773ff76e6d47d1d13b4c69713 to your computer and use it in GitHub Desktop.
Google App Script to decline events over a date range
// https://www.jasonmadigan.com/2017/07/03/declining-google-calendar-events-en-masse/
function GCalHoliday() {
var fromDate = new Date('July 17, 2017 00:00:00 +0100');
var toDate = new Date('August 8, 2017 23:30:00 +0100');
var calendarName = '<Your Calendar - e.g. [email protected]>';
var calendar = CalendarApp.getCalendarsByName(calendarName)[0];
var events = calendar.getEvents(fromDate, toDate, {});
Logger.log('Events: ' + events.length);
for (var i = 0; i < events.length; i++) {
var ev = events[i];
// try/catch for setting status - may get exceptions where events
// are on calendar, but user is not a "guest" of the event - these can be ignored
try {
// !!!
// ev.setMyStatus(CalendarApp.GuestStatus.NO); // Uncomment to actually update status
// !!!
} catch (e) {
Logger.log('Error updating event status ' + e);
}
Logger.log('Item ' + ev.getTitle() + ' found on ' + ev.getStartTime() + ' marked as declined');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment