Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added option for event color #17

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 17 additions & 6 deletions SyncCalendarsIntoOne.gs
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
// Calendars to merge from.
// "[X]" is what is placed in front of your calendar event in the shared calendar.
// Calendar name is a friendly way to identify your calendars.
//
// Id is the google calendar id found in the calendar setting
//
// Prefix "[X]" is what is placed in front of your calendar event in the shared calendar.
// Use "" if you want none.
//
// Color id for the events. Don't specify a color for the default color.
// 0=default, 1=blue, 2=green, 3=purple, 4=red, 5=yellow, 6=orange,
// 7=turquoise, 8=gray, 9=bold blue, 10=bold green, 11=bold red
const CALENDARS_TO_MERGE = {
'[Personal]': '[email protected]',
'[Work]': '[email protected]',
'Personal': {'id': '[email protected]', 'prefix':'[Personal]', 'color_id': ''},
'Work': {'id': '[email protected]', 'prefix':'[Work]', 'color_id': '4'},
};

// The ID of the shared calendar
Expand Down Expand Up @@ -81,8 +89,10 @@ function deleteEvents(startTime, endTime) {
function createEvents(startTime, endTime) {
let requestBody = [];

for (let calendarName in CALENDARS_TO_MERGE) {
const calendarId = CALENDARS_TO_MERGE[calendarName];
for (const [calendarName, calendarOption] of Object.entries(CALENDARS_TO_MERGE)) {
const calendarId = calendarOption.id;
const calendarPrefix = calendarOption.prefix;
const calendarColorId = calendarOption.color_id || '0';
const calendarToCopy = CalendarApp.getCalendarById(calendarId);

if (!calendarToCopy) {
Expand Down Expand Up @@ -113,11 +123,12 @@ function createEvents(startTime, endTime) {
method: 'POST',
endpoint: `${ENDPOINT_BASE}/${CALENDAR_TO_MERGE_INTO}/events`,
requestBody: {
summary: `${SEARCH_CHARACTER}${calendarName} ${event.summary}`,
summary: `${SEARCH_CHARACTER}${calendarPrefix} ${event.summary}`,
location: event.location,
description: event.description,
start: event.start,
end: event.end,
colorId: calendarColorId
},
});
});
Expand Down