Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
531 views
in Technique[技术] by (71.8m points)

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

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...