Last active
June 14, 2017 18:48
-
-
Save leoherzog/d0b333c7561473967602867d0b80724f to your computer and use it in GitHub Desktop.
Google Calendar Event Deleter - Remove all events on your calendar that were created by a certain id
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
| function run() { | |
| findAndNuke("blah@gmail.com"); | |
| } | |
| /** | |
| * This simple script gets all of your events on your calendar and deletes any that were created by "id". | |
| * Useful for rogue events created by email addresses that don't exist anymore. | |
| * | |
| * @param {string} id (email address) of the creator of the events you want to get rid of | |
| */ | |
| function findAndNuke(id) { | |
| if (!id || typeof id != "string" || !(validateEmail(id))) { | |
| throw "Please call this function with a valid Google Calendar ID"; | |
| } | |
| var beginningOfTime = new Date(1970,0,1); | |
| var aLongTimeFromNow = new Date(2100,0,1); | |
| var events = CalendarApp.getDefaultCalendar().getEvents(beginningOfTime, aLongTimeFromNow); | |
| Logger.log(events.length + " total events found. Searching for ones owned by " + id); | |
| // go through each event | |
| var eventsOwnedByPerson = []; | |
| for (var i in events) { | |
| // get it's creator(s) | |
| var creators = events[i].getCreators(); | |
| //go through the creator(s) of this one event | |
| for (var j in creators) { | |
| // if the creator of the event is the email that we're looking for | |
| if (id == creators[j]) { | |
| Logger.log("Found event named \"" + events[i].getTitle() + "\", created by " + id + ". Deleting..."); | |
| events[i].deleteEvent(); | |
| } | |
| } | |
| } | |
| } | |
| // https://stackoverflow.com/a/46181/2700296 | |
| function validateEmail(email) { | |
| var re = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/; | |
| return re.test(email); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment