Run a Gmail Google Apps Script daily at 8:00, 12:30, 17:00

ぐ巨炮叔叔 提交于 2020-03-23 08:57:27

问题


I need to run a Google Apps script three times a day: at 8:00, 12:30, 17:00.

How to do this?

I have already looked at Triggers, and more specifically Time driven:

  • Hour timer, but Every hour, Every 2 hours, Every 4 hours are not adapted here

  • Day timer, but then 8am to 9am is not very precise, I would prefer something more precise, and also 12:30 is not possible

  • Specific time, but then YYYY-MM-DD HH:MM is not adapted to run it daily

From calendar triggers does not seem adapted either.


回答1:


Use nearMinute() and atHour():

const createTrigger = ([hour, minute])=>
  ScriptApp.newTrigger("myFunction")
  .timeBased()
  .atHour(hour)
  .nearMinute(minute)  
  .everyDays(1) 
  .create();

[[8,0],[12,30],[17,0]].forEach(createTrigger)


来源:https://stackoverflow.com/questions/60773329/run-a-gmail-google-apps-script-daily-at-800-1230-1700

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!