javascriptgoogle-apps-scripttriggersgoogle-apps

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:

From calendar triggers does not seem adapted either.


Solution

  • 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)