What is Google Apps Script
Google Apps Script is a cloud JavaScript platform built into Google Workspace. You write functions in a browser editor (Extensions, Apps Script in Sheets) and they can read and write spreadsheets, send Gmail, create Drive files and run on triggers, with no server to host and nothing to install.
Syntax
function myFunction() { /* uses SpreadsheetApp, GmailApp, DriveApp, CalendarApp */ }| Part | What it is |
|---|---|
SpreadsheetApp | Service for Google Sheets: spreadsheets, sheets, ranges, values and formatting |
GmailApp / MailApp | Send and search email; MailApp only sends |
DriveApp | Files and folders in Google Drive |
CalendarApp | Events and calendars |
UrlFetchApp | HTTP requests to any API |
Examples
function hello() {
SpreadsheetApp.getActiveSheet().getRange("A1").setValue("Hello from Apps Script");
}Result: Cell A1 of the active sheet now reads Hello from Apps Script
Run it from the editor toolbar; the first run asks you to authorize access to the spreadsheet.
function countRows() {
const sheet = SpreadsheetApp.getActiveSheet();
Logger.log(sheet.getLastRow());
}Result: Logs the number of the last row with data, for example 42
function whoAmI() {
Logger.log(Session.getActiveUser().getEmail());
}Result: Logs the email address running the script (may be blank in some domains)
Common mistakes
- Nothing happens when you click Run: you selected the wrong function in the dropdown next to the Run button, so pick the function you just wrote.
- Authorization required pops up every first run of a new service: that is normal, review the scopes and click Allow.
- Script works in the editor but not for a colleague: a bound script belongs to the spreadsheet, so share the sheet with edit rights and they can run it too.
- Exceeded maximum execution time: a simple trigger stops at 30 seconds and a normal run at 6 minutes, so batch your reads and writes.
Practice What is Google Apps Script
These drills check your answer on live data, free, no account needed.
- Total of a listReturn the total of an array of numbers. An empty array totals `0`. Numbers can be negative or have decimals.
Questions
Is Google Apps Script the same as JavaScript?
Yes. Apps Script runs modern JavaScript (the V8 runtime) with extra Google services added. Arrow functions, const and let, template literals, map and filter all work.
Is Apps Script free?
Yes for any Google account. Free accounts have lower daily quotas (for example about 100 emails per day) than Google Workspace accounts.
Where do I open the editor in Google Sheets?
Open the spreadsheet, then Extensions, Apps Script. The script that opens is bound to that spreadsheet.
Related
- Your first Apps ScriptWrite and run your first Google Apps Script in Sheets: open the editor, write a function that reads and writes cells, run it, authorize it and read the log.
- Custom functionsCreate a custom function in Google Sheets with Apps Script: any function becomes a formula like =DOUBLE(A1), ranges arrive as 2D arrays, JSDoc adds help.
- Logger.log and console.logDebug Google Apps Script with Logger.log and console.log: where output appears, format placeholders, logging arrays and objects with JSON.stringify, logs.
- getActiveSheet vs getSheetByNameChoose between getActiveSheet and getSheetByName in Google Apps Script: when the active sheet is unreliable, targeting a tab by name, and missing sheets.