Run a function every day at a set hour
Apps Script recipes › Triggers and long jobs
Installs one time trigger for a function, removing older ones for it first so it never runs twice.
File Code.gs
function installDaily() {
ScriptApp.getProjectTriggers()
.filter(t => t.getHandlerFunction() === 'dailyJob')
.forEach(t => ScriptApp.deleteTrigger(t));
ScriptApp.newTrigger('dailyJob').timeBased().everyDays(1).atHour(7).create();
return 'dailyJob runs every day between 07:00 and 08:00.';
}
function dailyJob() {
// What should happen every morning, e.g. email the items that are due.
}
Good to know
- Run installDaily() once. The hour is in the script's time zone; Google picks a minute within that hour.
- A trigger runs as the person who installed it, with their email quota.
Let the AI put it in your appGAS AI Builder knows every recipe here. Describe your app and it uses this code where it fits, in a Google Apps Script project in your own Drive.
Use it in a project