Triggers are what make Apps Script truly powerful — they let your code run automatically in response to events, without anyone clicking a button. Here's a complete guide to all trigger types.
Simple triggers
Simple triggers are built-in functions that Apps Script recognises by name and runs automatically. No setup required — just define the function.
// Runs when the spreadsheet is openedfunctiononOpen(e){SpreadsheetApp.getUi().createMenu('Custom Menu').addItem('Run Report','runReport').addToUi();}// Runs when a cell is editedfunctiononEdit(e){const range = e.range;Logger.log(`Edited: ${range.getA1Notation()} = ${range.getValue()}`);}// Runs when the spreadsheet is changed (including programmatic changes)functiononChange(e){Logger.log('Change type: '+ e.changeType);}// Runs when a form is submitted (from a bound form)functiononFormSubmit(e){Logger.log('Form submitted: '+JSON.stringify(e.namedValues));}
Cannot be used in standalone scripts (only container-bound).
Installable triggers
Installable triggers overcome simple trigger limitations. They run with the script owner's authorisation and can perform any action.
Create programmatically
functioncreateInstallableOnEdit(){const ss =SpreadsheetApp.getActiveSpreadsheet();ScriptApp.newTrigger('onEditInstallable').forSpreadsheet(ss).onEdit().create();}functiononEditInstallable(e){// Can now send emails, access Drive, etc.if(e.range.getColumn()===5&& e.value==='Done'){GmailApp.sendEmail('[email protected]','Task completed',`Row ${e.range.getRow()} marked done.`);}}
Create via the UI
Open the script editor.
Click the Triggers icon (clock) in the left sidebar.
Click + Add Trigger.
Configure the function, event source, and event type.
Time-based triggers
Run code on a schedule — every minute, hourly, daily, or weekly.
functioncreateTimeTriggers(){// Every 5 minutesScriptApp.newTrigger('checkAlerts').timeBased().everyMinutes(5).create();// Every hourScriptApp.newTrigger('syncData').timeBased().everyHours(1).create();// Every day at 8 AMScriptApp.newTrigger('sendDailyReport').timeBased().everyDays(1).atHour(8).create();// Every Monday at 9 AMScriptApp.newTrigger('sendWeeklyReport').timeBased().onWeekDay(ScriptApp.WeekDay.MONDAY).atHour(9).create();// First of every month at 7 AMScriptApp.newTrigger('monthlyReport').timeBased().onMonthDay(1).atHour(7).create();}
Form submit triggers
functioncreateFormTrigger(){const form =FormApp.openById('YOUR_FORM_ID');ScriptApp.newTrigger('handleFormSubmit').forForm(form).onFormSubmit().create();}functionhandleFormSubmit(e){const email = e.response.getRespondentEmail();Logger.log('New submission from: '+ email);}