October 22, 2026

AI Google Apps Script: Automate Sheets, Docs and Gmail

AI Google Apps Script cover with a dark terminal window showing a function onOpen line

AI Google Apps Script is the quickest way for a non-developer to automate Sheets, Docs and Gmail: you describe the chore in plain words, the assistant writes the script, and you paste it into the editor that is already built into your Google account. Typical wins are sending a personalised e-mail for every row in a sheet, cleaning up a messy column on a schedule, turning form answers into a document, or adding a custom menu that does in one click what used to take ten.

The catch is that a script runs with your permissions on your real files and your real mailbox. This guide shows how to get a working script from an assistant, how to test it safely, and where the traps are: authorisation prompts, quotas, triggers and a few lines that can do damage if you do not read them.

What Google Apps Script is, in two minutes

Apps Script is a JavaScript-based scripting platform attached to Google Workspace. A script can be “bound” to a spreadsheet, document or form, so it opens with that file, or it can be a standalone project. It talks to Google services through built-in objects such as SpreadsheetApp, DocumentApp, GmailApp, DriveApp and CalendarApp. You open the editor from the Extensions menu in Sheets or Docs, write or paste code, save, and run it. Official documentation lives at developers.google.com/apps-script, and it is the source to check when anything the assistant produced looks unfamiliar.

You need no server, no installation and no deployment pipeline for the common cases, which is exactly why it suits a general assistant: the whole program is usually 20 to 80 lines in a single file.

The prompt pattern that gets a script that works

A vague request (“automate my spreadsheet”) produces a generic script that refers to columns you do not have. Give the assistant the facts a developer would ask for. The general method is in how to get working code from an AI assistant; for Apps Script, five items matter most.

  1. Where the script lives. “Bound to a Google Sheet” or “standalone”.
  2. The exact structure of the data. Sheet name, header row, column letters and what each holds. Paste the header row, never real customer data.
  3. The trigger. Run by hand from a menu, on edit, on form submission, or on a time schedule.
  4. The side effects allowed. Which cells may be written, whether e-mail may be sent, whether anything may be deleted. Say “never delete or overwrite existing data”.
  5. How you want to be told. A toast message, a log line, a status column in the sheet.

A prompt you can adapt

Write a Google Apps Script bound to a Google Sheet. Sheet name: “Orders”. Row 1 is a header. Columns: A order number, B customer e-mail, C status, D reminder sent. For every row where C is “Awaiting payment” and D is empty, send a plain-text reminder e-mail from my account using GmailApp, then write today’s date in D. Add a custom menu “Reminders” with one item that runs it. Process at most 20 rows per run, never delete or overwrite other cells, and show a message at the end saying how many e-mails were sent.

Notice the limits: a maximum per run, a protected set of cells, and a visible result. Those lines turn a risky script into a controllable one.

A small example you can read in full

Here is the kind of code the prompt above produces. Reading it line by line is the habit that keeps you safe.

function onOpen() {
  SpreadsheetApp.getUi()
    .createMenu('Reminders')
    .addItem('Send payment reminders', 'sendReminders')
    .addToUi();
}

function sendReminders() {
  const sheet = SpreadsheetApp.getActive().getSheetByName('Orders');
  const rows = sheet.getDataRange().getValues();
  let sent = 0;
  for (let i = 1; i < rows.length && sent < 20; i++) {
    const [order, email, status, reminded] = rows[i];
    if (status === 'Awaiting payment' && !reminded && email) {
      GmailApp.sendEmail(email, 'Reminder: order ' + order,
        'Hello,\n\nOrder ' + order + ' is still awaiting payment.\n\nThank you.');
      sheet.getRange(i + 1, 4).setValue(new Date());
      sent++;
    }
  }
  SpreadsheetApp.getActive().toast(sent + ' reminder(s) sent');
}

What to check: the sheet name matches exactly; the loop starts at index 1 so the header is skipped; the cap of 20 is enforced; the only write is a date in column D (the fourth column); and the only outward effect is sendEmail. Nothing is deleted. If any of those facts is wrong for your sheet, say so and ask for a corrected version rather than editing blind.

Everyday AI Google Apps Script jobs, ranked by risk

Not all automations are equal. Start with the ones that only read or write inside the file you are in, and work up to the ones that send or delete things.

Job What it touches Risk First test
Clean text in a column (trim, case, duplicates marked) Cells in one sheet Low Run on a copy of the sheet
Custom menu that formats a report Formatting in one file Low Run on a duplicate tab
Form answers to a filled-in Google Doc Creates new Docs in Drive Medium Submit a test form entry
Daily summary e-mail to yourself Sends mail to your own address Medium Send to yourself only for a week
Reminder e-mails to customers Sends mail to other people High Use a test sheet with your own addresses
Moving or deleting files in Drive Files outside the sheet High Log what would be moved before moving anything

For the high-risk rows, add a “dry run” switch: a variable at the top of the script that, when true, writes what it would do to the log and does nothing else. Ask the assistant for it explicitly.

Triggers: how a script runs without you

A script that needs you to click a menu is useful; one that runs on its own is where the time savings are. Apps Script offers simple triggers such as onOpen and onEdit that run automatically with limited permissions, and installable triggers that run on a schedule, on form submission or on calendar changes with your full authorisation. The official page on triggers explains the differences.

Three practical points. First, onEdit fires on every edit, so a slow script there makes the sheet feel broken; keep it tiny and check which cell changed before doing anything. Second, time-driven triggers run when you are not looking, so make the script write a log row or send you a summary so you notice if it stops. Third, a trigger created under your account stops working if the account is removed, so for a team process use a shared owner account and write down who owns it.

Authorisation: read the permission screen

The first time you run a script, Google asks you to authorise it. The screen lists what the script can do, such as “see, edit, create and delete your spreadsheets” or “read, compose, send and permanently delete all your e-mail from Gmail”. Those scopes follow from the services the code uses. If your goal is to send reminders and the screen asks for permanent deletion of all mail, ask the assistant why the script needs that scope and whether a narrower service call is possible. Never authorise a script you did not write or understand, and be especially careful with code copied from forums.

The same caution applies to Ask Mio itself: the assistant writes the code, but it does not hold your Google permissions, and it does not need to. You paste the script into your own editor and you decide whether to authorise it.

Quotas and limits you will hit

Apps Script is free to use but metered. Daily limits cap how many e-mails a script can send, how long one execution may run and how many triggers you can have; the exact numbers differ between consumer and Workspace accounts and change over time, so read the current quotas page instead of trusting a figure from memory, ours included.

The most common failure is the execution time limit on a large sheet. The usual cure is to read all the data once with getValues() and write it back once with setValues(), instead of reading and writing cell by cell inside a loop. Google’s best practices page explains this batching. If a script is slow, paste it into the assistant, say it times out on 5,000 rows, and ask for a batched version.

Testing without hurting anything

  1. Work on a copy. File, then Make a copy, and attach the script to the copy.
  2. Use fake data. Rows with your own addresses and invented names. Real customer data in a test is how the wrong person gets a test message.
  3. Log before you act. Add console.log lines for each decision and read the execution log.
  4. Run once, check, run again. Verify the first run’s results by eye before turning on a trigger.
  5. Keep a version. Use the editor’s version history, or paste the working script into a note, before asking the assistant to change it.

When something fails, paste the exact error text and the few lines around it back to the assistant. The method in how to debug code from an error message using AI applies unchanged. Common messages are “Cannot read properties of null” (usually a wrong sheet name), “Exception: Service invoked too many times” (a quota) and “Authorization is required” (a scope that was not granted).

When not to trust the generated script

Assistants are good at Apps Script because the platform is small and well documented, but they still make characteristic mistakes. They invent method names that look right but do not exist; they assume a column layout you never gave them; they forget that time-zone handling differs between the script and the sheet; and they sometimes use an old service name that Google has replaced. Our article on when not to trust AI-generated code lists the general warning signs, and the habit of asking for a review of the code before you run it catches many of them. A useful trick is to ask the assistant to explain each line in plain language: wherever the explanation does not match your intention, you have found the bug.

Where Ask Mio fits in this workflow

Ask Mio’s Code mode writes and explains the script, fixes it from a pasted error and refactors it when it grows. Code mode is available on the Coding plan at €12 a month and on the Business plan at €29 a month; you can also try short scripts in Chat mode on the free plan. A coding answer costs 5 to 10 points, so 6,000 points on the Coding plan go a long way for this kind of work. The Python and Node sandbox in Mio runs those languages, not Apps Script, so you will test the script in Google’s editor, not in Mio. If you also want spreadsheet formulas rather than scripts, see AI Excel formula generator; formulas are safer for simple calculations, scripts for actions.

Prices come from the live pricing page, are in EUR and have 21% VAT added at checkout.

A short checklist before you press Run

  • I know which sheet, columns and trigger the script uses.
  • I read every line that sends, deletes, moves or shares something.
  • There is a cap per run and a visible result message.
  • I tested on a copy with fake data and my own addresses.
  • I checked the authorisation screen and the scopes make sense.
  • I know who owns the trigger and who will notice if it stops.

Frequently Asked Questions

Can AI write a Google Apps Script for me?

Yes. Describe where the script lives, the sheet and column layout, the trigger and what it may change, and an assistant can produce a working script in seconds. Read it before running it, test on a copy with fake data, and paste any error message back so the assistant can correct it.

Do I need to know JavaScript to use an AI-written script?

Not to run one, but you should be able to read it. Apps Script is JavaScript, and short scripts are readable with a little patience. Ask the assistant to explain each line in plain language and to add comments; wherever the explanation differs from what you wanted, ask for a fix.

Is it safe to let a script send e-mail from my Gmail account?

It is safe if you control it. Cap the number of messages per run, test with your own addresses first, add a column that records what was sent, and read the authorisation screen. Check the current sending quotas, because exceeding them stops the script and can disrupt your mail for the day.

Why does my script say “Service invoked too many times”?

You hit a quota, usually because the script reads or writes cells one at a time inside a loop. Read the whole range once with getValues, process the data in memory and write it back once with setValues. If the problem is a daily e-mail or runtime limit, split the work across days.

Can Ask Mio run the script for me?

No. Ask Mio writes, explains and debugs the code, but the script runs inside your own Google account, which is also what keeps your permissions in your hands. Mio’s code sandbox runs Python and Node, so use it for those languages and test Apps Script in Google’s editor.

Should I use a formula or a script?

Use a formula when the task is a calculation that updates live, such as totals, lookups and conditional values. Use a script when the task is an action: sending a message, creating a file, running on a schedule or changing many cells at once. If either would work, choose the formula, because it is easier to audit.

The Bottom Line

AI Google Apps Script turns repetitive spreadsheet and mailbox chores into one-click or scheduled jobs, and the assistant does the typing. Your part is the briefing, the reading and the testing: give it the exact sheet layout, set limits on what the script may touch, run it on a copy with fake data and read the permission screen. Begin with a read-only or in-sheet job, add a dry-run switch for anything that sends or deletes, and grow from there. To try it, pick an Ask Mio plan that includes Code mode, or start on the free plan with a small script in Chat.


Try Ask Mio free

Free plan, no card required.

Start free