简体   繁体   English

Google Script 全天日历事件,当天有通知

[英]Google Script All Day Calendar Event with Notification On The Day

I have a script working fine however, I cannot work out how to add a popup reminder for after an all day event as started.... example: All day even is midnight to midnight, I want a notification at 9am that day.我有一个脚本工作正常但是,我不知道如何在开始的一整天事件之后添加弹出提醒....例如:一整天甚至是午夜到午夜,我想在那天早上 9 点收到通知。

my script uses event.addPopupReminder but this seems like it only works for before the event.我的脚本使用 event.addPopupReminder 但这似乎只适用于事件之前。 When I manually look, you have the option to add a reminder "On the day at 9am" but how do I code this?当我手动查看时,您可以选择添加提醒“当天上午 9 点”,但我该如何编码呢? using -900 within the code does not work在代码中使用 -900 不起作用

On the day at 9am当天上午9点

(I've snipped the code) (我截了代码)

By default, if the cell is blank, it'll add a notification at 9am the day before, which I want to change to 9am on the day默认情况下,如果单元格为空,它将在前一天的上午 9 点添加通知,我想将其更改为当天的上午 9 点

   if (C2 == "") {C2 = '900'}
   event.addPopupReminder(C2)

On the spreadsheet, I've entered -900 (for 9am on the day) and -1000 (for 10am on the day), neither have worked.在电子表格上,我输入了 -900(当天上午 9 点)和 -1000(当天上午 10 点),但均无效。

The function you are asking doesn't exist, but there is a way to do it anyway.您要求的 function 不存在,但无论如何都有办法做到这一点。 You just have to calcul the minutes between 9am and the start of your event manually.您只需手动计算上午 9 点和活动开始之间的分钟数。

You haven't put a lot of code, so I wrote something that probably need to be adapted to your case.你没有放很多代码,所以我写了一些可能需要适应你的情况的东西。

What the following function do:以下 function 做什么:

  • Get all events of the day and for each:获取当天的所有事件以及每个事件:
  • Define the minutes between 9am and the start time定义上午 9 点和开始时间之间的分钟数
  • Add a reminder添加提醒
function setReminderTodayEvents() {

  var today = new Date();
  today.setHours(9);
  today.setMinutes(0);
  today.setSeconds(0);

  var events = CalendarApp.getDefaultCalendar()
                          .getEventsForDay(today);

  for (var x = 0; x < events.length; x++) {
    var date_start = events[x].getStartTime();
    var delta = (date_start - today) / 1000 / 60; //ms to minute
    events[x].addPopupReminder(delta);
  }
}

Suggestion: add a trigger to execute that function every day between 7 and 8建议:添加一个触发器,每天7点到8点执行那个function

References:参考:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用Apps脚本将颜色更改为Google日历中的全天活动 - Change color to an All Day Event in google calendar with Apps script Google Script Calendar事件结束时间超过了所有日常事件 - Google Script Calendar event end time overrun on all day events Google Apps Script Calendar Service:获取重复(全天)事件的开始日期 - Google Apps Script Calendar Service: Get the start date of a recurring (all day) event 来自工作表脚本的 Google 日历活动提前一天结束 - Google Calendar event from sheets script ends a day early Google脚本创建全天日历条目 - Google script to create all-day calendar entries 无法通过Google表单在Google日历中创建全天活动系列 - Cannot create an all day event series into google calendar, from google forms Google Apps Script Calendar Service:仅获取所有重复(全天)事件中的第一个事件 - Google Apps Script Calendar Service: Get only the first events of all recurring (all day) events 从 Google 表格中的日期列表创建循环全天日历事件 - Create Recurring All Day Calendar Event from List of Dates in Google Sheet GoogleApp脚本。 显示当前活动的Google日历脚本 - GoogleApp script. Google calendar script that display current day events Google 日历删除多日活动的开始日期 - Google Calendar Remove Start Date for Multi Day Event
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM