Create Task with due date and time?

47 views
Skip to first unread message

Owen Chen

unread,
Mar 23, 2026, 6:19:43 PM (12 days ago) Mar 23
to Google Apps Script Community
It is possible to manually create a task in google calendar with a time associated with it, but is it possible to do so with a script?

Joseph Vaughan

unread,
Mar 23, 2026, 7:58:54 PM (12 days ago) Mar 23
to google-apps-sc...@googlegroups.com
Your script would need to use the tasks api and create a task with a due date. 

If your user has the tasks layer checked in the left side bar of the calendar, then the tasks that have a due date will appear on the calendar view. 

See the docs for the tasks service, which is the Google Apps script wrapper for the tasks API. 

Joseph
---------------
Joseph Vaughan
CIO/VP for Computing and Information Services
Harvey Mudd College


On Mon, Mar 23, 2026 at 3:19 PM Owen Chen <owenc...@gmail.com> wrote:
It is possible to manually create a task in google calendar with a time associated with it, but is it possible to do so with a script?

--
You received this message because you are subscribed to the Google Groups "Google Apps Script Community" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-apps-script-c...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/google-apps-script-community/18a5d4f3-26b0-4f18-a18e-1366edae3247n%40googlegroups.com.

Michael Bingham-Hawk

unread,
Mar 23, 2026, 9:54:31 PM (12 days ago) Mar 23
to google-apps-sc...@googlegroups.com
Have you installed workspace cli? It just came out two weeks ago, and it revolutionizes everything. You would also need to install Gemini cli. I am deploying those along with appscript. 


Michael Bingham-Hawk, Director of Race Timing
HIGH ALTITUDE SPECIAL EVENTS MANAGEMENT

Event Management | Race Timing | Equipment Rental
Media & Marketing | Athlete Photography | Large Event Internet Services
mic...@highaltitudeevents.com
720-608-4725 office
303-656-0732 mobile

www.HighAltitudeEvents.com



David Soule

unread,
Mar 23, 2026, 10:13:06 PM (12 days ago) Mar 23
to google-apps-sc...@googlegroups.com
This is how I do it. Hope this helps. 


  let cal = CalendarApp
    .getCalendarById(id)
  if (!cal) {
    createCalIfNotFound('foo');
    createCalIfNotFound('bar')
  }

  let event = cal.createEvent(msg, start, end,
    { location: 'Plex', description: desc, })

  if (!silent) {
    event
      .addPopupReminder(2)
      .addEmailReminder(5)
      .addSmsReminder(5);

    msg = msg.toString()
    if (msg.match(/lunch/)) {
      event.setColor(CalendarApp.EventColor.CYAN)
    }
    else if (msg.match(/break\d/)) {
      event.setColor(CalendarApp.EventColor.ORANGE)
    }
    else if (msg.match(/return/)) {
      event.setColor(CalendarApp.EventColor.GREEN);
    }
    else {
      event.setColor(CalendarApp.EventColor.MAUVE);
    }
  }
  else {
    event.removeAllReminders()
      .setDescription(desc)
  }

Ілля Чернов

unread,
Mar 24, 2026, 4:36:25 AM (12 days ago) Mar 24
to google-apps-sc...@googlegroups.com
Gmorning, ladies and gentlemans.
Ось виправлений та оптимізований скрипт. Я додав перевірку на
існування календаря (щоб код не "падав"), виправив логічну помилку з
викликом функцій створення і зробив код чистішим.
JavaScript

/**
* Створює подію в Google Календарі з автоматичним кодуванням кольором
та нагадуваннями.
* * @param {string} id - ID календаря.
* @param {string} msg - Назва події.
* @param {Date} start - Об'єкт Date початку.
* @param {Date} end - Об'єкт Date кінця.
* @param {string} desc - Опис події.
* @param {boolean} silent - Чи вимикати сповіщення.
*/
function createManagedEvent(id, msg, start, end, desc, silent) {
let cal = CalendarApp.getCalendarById(id);

// 1. Перевірка наявності календаря
if (!cal) {
console.error("Календар з ID " + id + " не знайдено. Спробуйте
використати 'primary'.");
// Якщо у вас є функція створення календаря, її можна викликати тут:
// cal = createCalIfNotFound('Work');
return; // Зупиняємо виконання, якщо календаря немає
}

// 2. Створення події
let event = cal.createEvent(msg, start, end, {
location: 'Plex',
description: desc
});

// Перетворюємо назву в рядок для надійної перевірки match()
let subject = msg.toString().toLowerCase();

// 3. Логіка сповіщень та кольорів
if (!silent) {
// Додаємо стандартні нагадування
event.addPopupReminder(2)
.addEmailReminder(5);

// Встановлюємо колір залежно від змісту (використовуємо RegExp
для точності)
if (/lunch/.test(subject)) {
event.setColor(CalendarApp.EventColor.CYAN); // Блакитний
}
else if (/break\d/.test(subject)) {
event.setColor(CalendarApp.EventColor.ORANGE); // Помаранчевий
}
else if (/return/.test(subject)) {
event.setColor(CalendarApp.EventColor.GREEN); // Зелений
}
else {
event.setColor(CalendarApp.EventColor.MAUVE); // Бузковий
}
}
else {
// "Тихий" режим: видаляємо все зайве
event.removeAllReminders();
}

console.log("Подію створено: " + msg);
}

// Приклад виклику функції:
// createManagedEvent('ваш_id_тут', 'Lunch with Team', new Date(), new
Date(Date.now() + 3600000), 'Meeting at Plex', false);

вт, 24 бер. 2026 р. о 10:13 David Soule <sirdave...@gmail.com> пише:
> To view this discussion visit https://groups.google.com/d/msgid/google-apps-script-community/CAD%2Bu0mzKnH%3DG0Ono%3DJ8oyk%2BAgN%3D-jZbn%3D3jrd1PsrFLV3os4Ew%40mail.gmail.com.



--
З найкращими побажаннями,
Ілля Чернов
Reply all
Reply to author
Forward
0 new messages