メインコンテンツにスキップ

TriggerApp

This is a Google Apps Script library for efficiently managing the time-driven triggers for executing Google Apps Script using Google Apps Script.

AI Summary

TriggerApp

A Google Apps Script library that manages complex time-driven triggers with a single configuration object.

Target Users

Intermediate-to-advanced Apps Script developers automating business workflows who need to configure multiple time-based triggers efficiently.

Problems Solved

Managing various scheduling scenarios usually requires many individual scripts or triggers, leading to complex maintenance and higher quota usage.

Tags

Main Features

1
Single-object trigger definition

Define daily, weekly, monthly, yearly or interval schedules by combining 12 properties such as ownFunctionName, functionName, everyDay, interval, etc.

2
Minimized trigger count

Its algorithm controls many tasks using at most two Apps Script triggers, reducing quota consumption.

3
Built-in schedule simulation

simulateTriggers() lets you preview execution times before installation, preventing configuration errors.

4
Flexible timing adjustment

Methods like setEase and setDiffTriggerTime allow fine-grained control of wait times and buffers between functions.

5
Trigger management utilities

Helper methods such as deleteAllTriggers() support bulk deletion and data-driven trigger installation.

Usage Examples

Minimal setup: run a function every day at 09:00

/**
 * Main entry: simulate and install the trigger.
 * `e` is the event object passed from the time-driven trigger.
 */
function main(e) {
  // Define the schedule with a single object
  const obj = [
    {
      ownFunctionName: 'main',      // this main function
      functionName: 'work',         // function to be executed
      everyDay: true,               // run every day
      atTimes: ['09:00:00']         // at 09:00
    }
  ];

  // 1) Preview upcoming executions
  const preview = TriggerApp.setEventObject(e).simulateTriggers(obj);
  console.log(preview);

  // 2) Install the real trigger after confirmation
  // TriggerApp.setEventObject(e).installTriggers(obj);
}

/**
 * Business logic executed by the trigger
 */
function work() {
  // Place your routine here
  SpreadsheetApp.getActiveSpreadsheet().toast('work executed');
}

Copy the snippet into your Apps Script project, run main once, and the library will schedule work to fire automatically at 09:00 every day.