[英]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 不起作用
(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 做什么:
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.