Skip to content

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

Change these values

Make the code yours before you run it.
Run hour
9

The trigger runs around this hour in the script project time zone.

Email subject
Daily script reminder

This is the subject delivered to the script owner.

Handler name
sendDailyReminder

The 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.

Code.gs
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

  1. 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.

  2. 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.

  3. 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.

  4. 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

Keep going