Unit 3 · Module 2
Triggers
Simple triggers, installable triggers, and the editor UI where they get configured
Why this page exists
Module 1 named “trigger” as one of the four parts of a script. This is the page where Apps Script’s specific trigger system gets pinned down. Without a trigger, a script just sits in the editor doing nothing.
The two kinds of triggers
| Simple triggers | Installable triggers | |
|---|---|---|
| How they’re set up | Just by naming the function a special reserved name | Configured in the editor UI (Triggers panel) |
| Function names | onOpen, onEdit, onSelectionChange, doGet, doPost | Any name the developer picks |
| What can trigger them | Only user-driven events in the bound document | Time-based, form submit, calendar events, etc. — anything Google supports |
| Permissions | Limited — can’t call services that require authorization (no sending email as the user, etc.) | Full — runs with the same permissions the developer authorized |
| Visible in code | Yes (the function exists with the magic name) | No — the trigger lives in the project settings, not the code |
Simple triggers, in code
A simple trigger is just a function with a reserved name. Apps Script sees the name and wires the trigger up automatically.
Apps Script — bound to a Sheet
function onOpen() {
SpreadsheetApp.getUi().alert("Welcome back");
}
function onEdit(e) {
const editedCell = e.range;
editedCell.setBackground("#ffeecc");
} onOpen runs every time the user opens the Sheet.
onEdit runs every time the user edits a cell. The developer
never writes “listen for opens.” The name is the contract.
The reserved names worth knowing
| Function name | Fires when |
|---|---|
onOpen(e) | User opens a Sheet, Doc, Form, or Slides bound to the script |
onEdit(e) | User edits a cell in the bound Sheet |
onSelectionChange(e) | User selects a different cell in the bound Sheet |
onInstall(e) | User installs the script as an add-on |
doGet(e) / doPost(e) | Script is deployed as a web app and receives an HTTP request (the standard way a browser or another app asks a server for something — covered in Unit 4) |
Installable triggers, in the UI
Installable triggers don’t appear in the code. They live in the Apps Script editor under Triggers (the clock icon in the sidebar). Each trigger is a row that says “run this function when this event happens.”
The event options Google offers:
- Time-driven. Every minute / hour / day / week / month / at a specific time
- From spreadsheet. On open / on edit / on change / on form submit
- From form. On open / on form submit
- From calendar. Calendar event updated
- From document. On open
The function the trigger calls is just a regular function in the script. It can have any name. The trigger is the configuration that wires “event X” to “function Y.”
Apps Script — function called by a daily installable trigger
function sendMorningSummary() {
const ss = SpreadsheetApp.openById("abc123");
const sheet = ss.getSheetByName("Orders");
const count = sheet.getLastRow() - 1;
GmailApp.sendEmail(
"me@example.com",
"Daily summary",
`Orders today: ${count}`
);
}
Nothing in this function says “run me daily.” That part lives in
the Triggers panel — a row that says “run sendMorningSummary,
time-driven, day timer, 7am–8am.”
The connection back to Module 1’s four parts
Simple triggers and installable triggers are both ways of filling in the fourth part of the anatomy from Module 1 — “what causes the entry point to run.” Apps Script just offers two flavors: one configured by function name, one configured in the UI.