Task guide
Run an Apps Script function every day
Make a function run on its own once a day. Run the setup function once, and from then on Apps Script calls the reminder function each day around the hour you chose.
1 · Prepare
Put these pieces in place
- Use an account that can send email through Gmail.
- Go to script.google.com and click New project, or use a project you already have. Keep both functions in the same project.
- Expect one email every day until you delete the trigger.
Change these values
- Run hour
9The trigger runs around this hour in the script project time zone.
- Email subject
Daily script reminderThis is the subject delivered to the script owner.
- Handler name
sendDailyReminderThe setup function checks this name before making another trigger.
2 · Review before running
What the script can access and change
Permissions you approve
- Allow this application to run when you are not present. This lets the script install its daily trigger and run each morning without you.
- Read, compose, send, and permanently delete all your email from Gmail. Google asks for full Gmail access because the code uses GmailApp, but the code only sends one reminder to your own address.
- See your primary Google Account email address. The code reads it to know where to send the reminder.
Effects of one run
- Creates one daily trigger, and only when a trigger for sendDailyReminder is not already installed.
- Sends the account that installed the trigger one reminder email each day, some time between 9 AM and 10 AM in the project time zone.
- Sends nothing to anyone else and changes no files.
3 · Copy
Paste this into the Apps Script editor
Create or open a script file, replace the example values marked above, then save the project.
const RUN_HOUR = 9; // The trigger runs around this hour in the script project time zone.
const EMAIL_SUBJECT = 'Daily script reminder'; // This is the subject delivered to the script owner.
const HANDLER_NAME = 'sendDailyReminder'; // The setup function checks this name before making another trigger.
function createDailyReminder() {
const alreadyInstalled = ScriptApp.getProjectTriggers().some((trigger) => {
return trigger.getHandlerFunction() === HANDLER_NAME;
});
if (alreadyInstalled) return;
ScriptApp.newTrigger(HANDLER_NAME)
.timeBased()
.everyDays(1)
.atHour(RUN_HOUR)
.create();
}
function sendDailyReminder() {
const recipient = Session.getEffectiveUser().getEmail();
GmailApp.sendEmail(recipient, EMAIL_SUBJECT, 'Your daily Apps Script reminder ran successfully.');
} 4 · Run
Follow these steps in order
Paste both functions and save
Paste both functions over the starter code and save. createDailyReminder installs the schedule. sendDailyReminder is the work that runs each day.
Test the reminder by hand
Choose sendDailyReminder in the function dropdown above the code, then click Run. Approve access when Google asks. One email with the subject Daily script reminder arrives in your inbox.
Run the setup function once
Choose createDailyReminder and click Run. Running it again does not add a second trigger, because it stops when a trigger for sendDailyReminder already exists.
Check the trigger list
Click Triggers, the clock icon in the left sidebar. sendDailyReminder is listed as a day timer. To stop the emails later, click the three dots at the end of that row and delete the trigger.
5 · Confirm
How to tell it worked
Triggers lists sendDailyReminder as a day timer, and an email with the subject Daily script reminder arrives each morning.
If the result is different
Troubleshooting
- Running createDailyReminder adds nothing to the trigger list.
- Open Triggers and look for an existing sendDailyReminder trigger. The setup function stops when one already exists.
- The email arrives at an unexpected time.
- Open Project Settings, the gear icon in the left sidebar, and check the time zone. Then delete the trigger under Triggers, change RUN_HOUR, save, and run createDailyReminder again. A day timer runs some time inside the chosen hour.
- No email arrives.
- Open Executions in the left sidebar to see whether sendDailyReminder ran and what it reported. If it says authorization is required, run sendDailyReminder by hand once and approve access.
Technical details
Names used in this script
Open these details when you want to adapt the example or look up an exact service or method name.
Show Apps Script symbols and service pages
Apps Script symbols
Keep going
Related tasks, basics, and apps
- Task guide Respond to a Google Form submission
Get an email every time someone submits your Google Form, listing each question and its answer. The email goes only to you, the owner of the script.
- Task guide Save labeled Gmail attachments to Drive
Copy the attachments from chosen Gmail conversations into one Drive folder. You pick the conversations by adding a label to them, and the script saves every attachment it finds there.
- Object reference Trigger
A ScriptApp.Trigger is one installed schedule or event rule in this project. ScriptApp.getProjectTriggers() returns only the installable triggers that belong to you, the user running the script. Use it to see which function a trigger runs, or delete a trigger with ScriptApp.deleteTrigger(). Other users must delete their own triggers.
- Object reference Trigger builder
ScriptApp.newTrigger(functionName) returns a TriggerBuilder that configures a timeBased(), forSpreadsheet(), or forForm() trigger before create() saves it.
- Basics Run your first Apps Script function
Your first script, from opening the editor to reading its output. You replace the starter function, save, click Run, and read what Logger.log printed in the Execution log.
- Basics Apps Script permissions and authorization
Before a script can read your sheet or send your mail, you give it permission to access a list of OAuth scopes. This page walks through each authorization screen, explains @OnlyCurrentDoc, and shows how to revoke access.
- Basics Google Apps Script triggers explained
Google Apps Script triggers run functions automatically when a file opens, a cell changes, a form is submitted, or a scheduled time arrives. Use a simple onEdit or onOpen for work in the bound file. Choose an installable trigger for a schedule, form submission, or work that needs authorization.
- Google app Triggers
A trigger is a saved schedule or event rule in ScriptApp that runs your function on time, on edit, or on form submit.
- Google app Gmail
GmailApp scripts can send messages, search threads, apply labels, and read attachments after you approve Gmail access for the project.