-
Notifications
You must be signed in to change notification settings - Fork 0
/
gcalToGTasks.gs
29 lines (25 loc) · 1.09 KB
/
gcalToGTasks.gs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
function syncEventsToTasks() {
// Change the calendar ID below to match the ID of the calendar you want to sync
var calendarId = 'your-calendar-id';
var taskListId = 'your-tasklist-id';
// Get all events from the calendar
var events = CalendarApp.getCalendarById(calendarId).getEvents(new Date(), new Date(new Date().setMonth(new Date().getMonth() + 1)));
// Get all tasks in the task list
var tasks = Tasks.Tasks.list(taskListId).items;
// Create an object to track the titles of existing tasks
var existingTitles = {};
for (var i = 0; i < tasks.length; i++) {
existingTitles[tasks[i].title] = true;
}
// Loop through each event and add it as a task if it doesn't already exist
for (var i = 0; i < events.length; i++) {
var event = events[i];
if (!existingTitles[event.getTitle()]) {
var task = Tasks.newTask();
task.title = event.getTitle();
task.notes = event.getDescription();
task.due = Utilities.formatDate(event.getStartTime(), Session.getScriptTimeZone(), "yyyy-MM-dd'T'HH:mm:ss'Z'");
Tasks.Tasks.insert(task, taskListId);
}
}
}