diff --git a/Code.gs b/Code.gs index e9579b6..3bd1fb8 100644 --- a/Code.gs +++ b/Code.gs @@ -6,7 +6,7 @@ * 1) Make a copy: * New Interface: Go to the project overview icon on the left (looks like this: ⓘ), then click the "copy" icon on the top right (looks like two files on top of each other) * Old Interface: Click in the menu "File" > "Make a copy..." and make a copy to your Google Drive -* 2) Settings: Change lines 24-50 to be the settings that you want to use +* 2) Settings: Change lines 24-67 to be the settings that you want to use * 3) Install: * New Interface: Make sure your toolbar says "install" to the right of "Debug", then click "Run" * Old Interface: Click "Run" > "Run function" > "install" @@ -21,14 +21,28 @@ *========================================= */ -var sourceCalendars = [ // The ics/ical urls that you want to get events from along with their target calendars (list a new row for each mapping of ICS url to Google Calendar) - // For instance: ["https://p24-calendars.icloud.com/holidays/us_en.ics", "US Holidays"] - // Or with colors following mapping https://developers.google.com/apps-script/reference/calendar/event-color, - // for instance: ["https://p24-calendars.icloud.com/holidays/us_en.ics", "US Holidays", "11"] - ["icsUrl1", "targetCalendar1"], - ["icsUrl2", "targetCalendar2"], - ["icsUrl3", "targetCalendar1"] - +var sourceCalendars = [ + + // The ics/ical urls that you want to get events from along with their target calendars (list a new row for each mapping of ICS url to Google Calendar) + // For instance: ["https://p24-calendars.icloud.com/holidays/us_en.ics", "US Holidays"] + + // Or with additional Options: + // - colorId: Colors of the Events with the following mapping https://developers.google.com/apps-script/reference/calendar/event-color + // - calendarName: Alternative name for the parent calendar + // for instance: + // ["https://p24-calendars.icloud.com/holidays/us_en.ics", "US Holidays", { + // colorId: "1", + // calendarName: 'Parent Calendar Name' + // }] + + ["icsUrl1", "targetCalendar1", { + colorId: "1", + calendarName: 'Parent Calendar Name 1' + }], + ["icsUrl2", "targetCalendar2", { + calendarName: 'Parent Calendar Name 2' + }], + ["icsUrl3", "targetCalendar3"], ]; var howFrequent = 15; // What interval (minutes) to run this script on to check for new events. Any integer can be used, but will be rounded up to 5, 10, 15, 30 or to the nearest hour after that.. 60, 120, etc. 1440 (24 hours) is the maximum value. Anything above that will be replaced with 1440. diff --git a/Helpers.gs b/Helpers.gs index 5f1e812..e0a7e81 100644 --- a/Helpers.gs +++ b/Helpers.gs @@ -205,7 +205,6 @@ function parseResponses(responses){ var result = []; for (var itm of responses){ var resp = itm[0]; - var colorId = itm[1]; var jcalData = ICAL.parse(resp); var component = new ICAL.Component(jcalData); @@ -215,13 +214,15 @@ function parseResponses(responses){ ICAL.TimezoneService.register(tz); } + var colorId = itm[1] && itm[1].colorId var allEvents = component.getAllSubcomponents("vevent"); if (colorId != undefined) allEvents.forEach(function(event){event.addPropertyWithValue("color", colorId);}); - var calName = component.getFirstPropertyValue("x-wr-calname") || component.getFirstPropertyValue("name"); - if (calName != null) - allEvents.forEach(function(event){event.addPropertyWithValue("parentCal", calName); }); + var calName = (itm[1] && itm[1].calendarName) || component.getFirstPropertyValue("x-wr-calname") || component.getFirstPropertyValue("name"); + if (calName != null) { + component.getAllSubcomponents("vevent").forEach(function(event){event.addPropertyWithValue("parentCal", calName); }); + } result = [].concat(allEvents, result); }