Google Apps Script · Beginner guide

Google Apps Script examples for Sheets, Gmail and Drive

Apps Script is the scripting tool built into Google Workspace. A few lines of it can clean up a spreadsheet, send emails from a list or file Drive attachments for you. This page has our Apps Script library and a 7-step guide to get any script running in your own account.

⏱ Setup time5–10 minutes
🎯 DifficultyBeginner friendly
💰 CostFree with a Google account
🧰 You needA Google account

What can you automate with Google Apps Script?

Anything you do by hand in Google's apps, on repeat. Here's what that looks like in each one.

📊

Google Sheets automation

Clean up imported data, build a weekly report, add a custom menu, or write your own formula like =AHREFS_DR(A2).

✉️

Gmail automation

Send personalised emails from a sheet, label incoming mail, or save attachments to Drive the moment they arrive.

📁

Google Drive automation

Rename and sort files, create folders for new clients, or turn a Docs template into a filled-in contract.

📝

Forms and Calendar

Email someone each time a form is submitted, or put new sign-ups straight onto a calendar.

Featured script

A good first script if you work in SEO.

How to install and run a Google Apps Script

The same seven steps work for every script in the library.

  1. 01

    Pick a script

    Open a script from the library and read three things first: what it does, which Google services it touches, and what permissions it will ask for.

  2. 02

    Copy or download the code

    Scripts come as a .gs or .txt file, or as a ZIP with several files. Unzip it first if needed.

  3. 03

    Open the Apps Script editor

    In the Google Sheet (or Doc or Form) you want to automate, go to Extensions, then Apps Script. For a standalone script, start a new project at script.google.com.

  4. 04

    Paste the code and save

    Replace the sample code in Code.gs, or add a new file if your project already has code. Give the project a name you'll recognise later.

  5. 05

    Change the settings

    Most scripts have a few values near the top to edit, such as a sheet name, a Drive folder ID or an email address. Keep API keys out of any file you share.

  6. 06

    Run it and approve access

    Choose the function and click Run. Google will list the permissions the script needs. Read them, and only continue if they match what the script is supposed to do.

  7. 07

    Put it on a schedule

    Open Triggers (the clock icon) and add a time-driven or event trigger, so the script runs every morning or every time a form comes in.

Before you run anything: make a copy of the sheet and test on that. If a script misbehaves, the original is untouched.

Try it: a 10-line script that counts rows

A safe first run. It reads the active sheet and logs how many rows sit under the header. It doesn't change or send anything.

Code.gsGoogle Apps Script
function countSpreadsheetRows() {
  const sheet = SpreadsheetApp
    .getActiveSpreadsheet()
    .getActiveSheet();

  // Row 1 is the header, so leave it out of the count.
  const dataRows = Math.max(0, sheet.getLastRow() - 1);

  console.log('Rows below the header: ' + dataRows);
  return dataRows;
}
How to run it: open any Google Sheet, go to Extensions, then Apps Script, paste the code, save, and run countSpreadsheetRows. The answer shows up in the Execution log.

Apps Script triggers: when a script runs on its own

Triggers are what turn a script you run by hand into an automation.

TriggerRuns whenTypical use
Time-drivenOn a schedule you set, from every minute to once a monthDaily reports, reminders, data syncs
On openSomeone opens the fileAdding a custom menu
On editA cell in the sheet is changedTimestamps, input checks
On form submitA Google Form gets a responseConfirmation emails, routing responses

Google limits how often triggers fire and how long each run can last. The official Apps Script quotas page has the current numbers.

Common Apps Script errors and how to fix them

Five messages cover most of the trouble people run into.

ErrorWhat usually causes it
Authorization requiredThe script needs your permission. Run it once from the editor and approve the access, if it matches what the script does.
Cannot read properties of nullThe script expected a sheet, file or value that isn't there. Check sheet names and IDs in the settings.
Exceeded maximum execution timeOne run tried to do too much. Process the data in smaller batches.
Service invoked too many timesYou've hit a daily Google quota. Cut down repeat calls or run the trigger less often.
ReferenceError: X is not definedA typo in a function name, or a file from the project is missing.

Google Apps Script FAQ

What people want to know before they run their first script.

Is Google Apps Script free?

Yes. Apps Script comes with every Google account at no extra cost. Google sets daily quotas, such as how many emails a script can send, and Google Workspace accounts get higher limits than personal Gmail accounts.

Do I need to know how to code?

Not to use the scripts in our library. You paste the code, change a few settings and click Run. You only need JavaScript if you want to change how a script works.

How do I use Apps Script in Google Sheets?

Open the sheet, go to Extensions, then Apps Script. Anything you write there is tied to that sheet, so it can read and change its data, add menus and create custom formulas.

Why does Google say "Google hasn't verified this app"?

Google shows that warning for scripts that haven't been through its app review, which is normal for scripts you add yourself. Only click through it if you've read the code and trust what it does.

How do I run a script automatically?

Add a trigger. In the Apps Script editor, open Triggers, click Add Trigger, then pick the function and when it should run, such as every day at 8am or whenever a form is submitted.

Is it safe to run a downloaded script?

It's as safe as the code itself. Read the script, check the permissions it asks for, test it on a copy of your data, and never paste passwords or API keys into a file other people can open.

Find a Google Apps Script for your next task

Browse the scripts in the library, or tell us what you'd like automated in Sheets, Gmail or Drive and we'll look at building it.