-
-
Save ngabyn/4cca9009d29f2ccd69d8d8d6c28f4cef to your computer and use it in GitHub Desktop.
Moving events from one calendar to another, using Google Apps Script
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * Move events with a given title from your primary calendar to another calendar. | |
| * You must enable the Calendar Advanced Service: | |
| * https://developers.google.com/apps-script/guides/services/advanced#enabling_advanced_services | |
| */ | |
| function moveEvents(eventTitle, fromCalendarName, toCalendarName) { | |
| var fromCalendarId = CalendarApp.getCalendarsByName(fromCalendarName)[0].getId(); | |
| var toCalendarId = CalendarApp.getCalendarsByName(toCalendarName)[0].getId(); | |
| var now = new Date(); | |
| var oneYearAgo = new Date(now); | |
| oneYearAgo.setYear(oneYearAgo.getYear() - 1); | |
| var pageToken = null; | |
| do { | |
| var results = Calendar.Events.list(fromCalendarId, { | |
| q: eventTitle, | |
| pageToken: pageToken | |
| }); | |
| results.items.filter(function(event) { | |
| return event.summary == eventTitle; | |
| }).forEach(function(event) { | |
| Calendar.Events.move(fromCalendarId, event.id, toCalendarId); | |
| console.log('Moved event ' + event.id); | |
| }); | |
| pageToken = results.nextPageToken; | |
| } while (pageToken) | |
| } | |
| function test() { | |
| moveEvents('Gym', 'Medical', 'Exercise'); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment