Google Apps Script TutorialGoogle Apps ScriptApps Script beginnersGoogle Sheets automationJavaScript automation

How to Create Your First Google Apps Script in 10 Minutes

Learn how to create your first Google Apps Script in 10 minutes by adding a custom menu and timestamp function to a Google Sheet.

Free Apps Script TeamAugust 25, 20268 min read
How to Create Your First Google Apps Script in 10 Minutes guide cover illustration
How to Create Your First Google Apps Script in 10 Minutes guide cover illustration

Want to automate a Google Workspace task but do not know where to start? This guide shows you how to create your first Google Apps Script in 10 minutes using a Google Sheet. You will create a small script that adds a custom menu and writes the current date and time into the active sheet. The example is intentionally simple, but it teaches the core Apps Script workflow: open the editor, write a function, authorize it, run it, and troubleshoot common errors.

What you will build

Workflow from opening a Google Sheet to using a custom menu to add a timestamp
The script adds a menu when the sheet opens, then writes a timestamp to the selected cell.

By the end of this tutorial, your spreadsheet will have a custom menu named My Tools. Selecting My Tools > Add timestamp will write the current date and time into the selected cell.

This example uses a bound script. A bound script is attached to one Google Sheet, Doc, or other Workspace file, so it can work with that file without requiring you to copy its ID into the code.

Before you start

  • Sign in to a Google account that can create or edit a Google Sheet.
  • Create a blank Google Sheet at sheets.google.com.
  • Use a sheet where you are comfortable adding a test value.
  • Keep the spreadsheet open in the same browser tab while you work.

You do not need to install anything. Google Apps Script runs in Google’s cloud and uses your Google account for authorization.

How to create your first Google Apps Script in 10 minutes

Google Sheets Extensions menu and Apps Script editor with a beginner timestamp script
Open Apps Script from Extensions in the Google Sheet, then paste the code into Code.gs.

1. Open the Apps Script editor

From your Google Sheet, select Extensions > Apps Script. A new Apps Script project opens in another browser tab, usually with a file named Code.gs.

Delete any sample code in the editor. Then paste the complete code below into Code.gs.

/**
 * Adds a custom menu when the spreadsheet opens.
 */
function onOpen() {
  SpreadsheetApp.getUi()
    .createMenu('My Tools')
    .addItem('Add timestamp', 'addTimestamp')
    .addToUi();
}

/**
 * Writes the current date and time into the selected cell.
 */
function addTimestamp() {
  const sheet = SpreadsheetApp.getActiveSheet();
  const cell = sheet.getActiveCell();

  cell.setValue(new Date());
  cell.setNumberFormat('yyyy-mm-dd hh:mm:ss');
}

2. Save the project

Click the Save project icon, or press Ctrl+S on Windows and ChromeOS or Cmd+S on macOS. If Google asks for a project name, use something descriptive such as First Timestamp Script.

The code contains two functions:

  • onOpen() creates the custom menu whenever the spreadsheet is opened.
  • addTimestamp() gets the active sheet and selected cell, then writes the current date and time there.

The onOpen function is a simple trigger. It normally runs when an editor or user opens the spreadsheet. The timestamp function is run from the custom menu after the spreadsheet interface has loaded.

3. Run the function once from the editor

At the top of the Apps Script editor, open the function selector and choose addTimestamp. Click Run.

The first run may display an authorization request. This is expected: the script needs permission to modify the spreadsheet you opened it from.

4. Review the authorization request

  1. Click Review permissions.
  2. Select the Google account that owns or can edit the spreadsheet.
  3. Review the requested access.
  4. If Google displays an unverified-app warning for this personal script, select Advanced, then choose the option to continue to your own project.
  5. Click Allow if you trust the code and understand what it does.

Only authorize code you can inspect and understand. This example does not send email, call an external service, or share your spreadsheet. It only reads the active spreadsheet context and writes a date value to the selected cell.

5. Test the script in your sheet

Return to the spreadsheet and refresh the browser tab. Select any cell, then choose My Tools > Add timestamp. The selected cell should contain a date and time.

If the value looks like a number rather than a date, select the cell and use Format > Number > Date time. The script also applies a date-time format, but spreadsheet locale and display settings can affect how the value appears.

Screenshot needed: Capture the Google Sheets Extensions menu with Apps Script visible, followed by the Apps Script editor containing the two functions. This helps beginners find the correct editor and confirm where the code belongs.

How the script works

Apps Script uses JavaScript syntax and Google-provided services. In this example, SpreadsheetApp is the service used to work with Google Sheets.

CodePurpose
SpreadsheetApp.getUi()Gets the spreadsheet interface so the script can create a menu.
createMenu('My Tools')Starts a custom menu with the label My Tools.
addItem('Add timestamp', 'addTimestamp')Adds a visible menu item and connects it to a function.
SpreadsheetApp.getActiveSheet()Gets the currently active worksheet.
sheet.getActiveCell()Gets the cell selected by the user.
cell.setValue(new Date())Writes the current date and time to the selected cell.

The function name in addItem must match the function you want to run. For example, changing 'addTimestamp' to a name that does not exist will cause the menu item to fail.

What to do if the menu does not appear

Apps Script Executions page used to diagnose a failed script run
Use Executions in the Apps Script editor to inspect recent runs and errors.

The menu is created by onOpen(), so it usually appears after the spreadsheet is refreshed or reopened. If it is missing:

  1. Confirm that the code was saved in the Apps Script project connected to this sheet.
  2. Return to the spreadsheet and refresh the browser tab.
  3. Check that the function is named exactly onOpen, including capitalization.
  4. Open Apps Script and select Executions to look for a recent error.
  5. Run onOpen manually from the editor if necessary, then return to the sheet.

When you run a function from the editor, the editor may be working with the active spreadsheet context. If you open the script as a standalone project instead of from the sheet, functions that depend on an active spreadsheet can behave differently. For this tutorial, always open the editor from Extensions > Apps Script in the target spreadsheet.

Common errors and fixes

“Authorization is required”

Run the function again and complete the permission flow. If you changed the code to use a new Google service, Apps Script may request additional access.

The script ran but wrote to the wrong cell

The function writes to the active cell at the moment it runs. Select the intended cell before using the custom menu. For a production workflow, it is usually safer to target a named range, a known column, or a validated range instead of relying on the user’s selection.

The timestamp does not match your local time

Spreadsheet display settings and the script project’s time zone can affect date formatting. Check the spreadsheet time zone under File > Settings and the project settings in Apps Script. Do not treat a displayed date as proof of the underlying time zone; verify the settings when time accuracy matters.

“Cannot call method” or a null-value error

This often means the script expected an active spreadsheet, sheet, or cell but did not receive one. Make sure the script is bound to the spreadsheet and that a cell is selected before running addTimestamp.

Screenshot needed: Capture the Apps Script Executions page showing where a failed run, error message, and timestamp can be reviewed. This gives readers a practical diagnostic location instead of guessing why a function failed.

Improve the example safely

Once the basic script works, you can adapt it to a real workflow. For example, you could add a “Last updated” timestamp to a task tracker, record when an invoice status changes, or create a custom menu for repetitive spreadsheet actions.

Before expanding the code, keep these practices in mind:

  • Read and write in batches: For many rows, use getValues() and setValues() rather than calling the spreadsheet service once per cell.
  • Validate input: Check that required cells contain the expected values before changing data.
  • Protect sensitive data: Do not hard-code passwords, API keys, or private tokens. Store secrets in Script Properties when an external service is genuinely required.
  • Keep permissions narrow: Avoid adding services or scopes that the automation does not need.
  • Log useful information: Use console.log() or the execution history while developing, but do not log personal or confidential data unnecessarily.

Simple scripts are often the easiest to maintain. Add a trigger, external API, or web app only when the workflow requires it.

When Apps Script is the right tool

Apps Script is a good fit for automations that live inside Google Workspace: updating Sheets, generating Docs, sending Gmail messages, processing Form responses, or running scheduled tasks. It is less suitable when you need a continuously running server, very high-volume processing, strict low-latency behavior, or a complex application with extensive user management.

For a larger workflow, start with a small manual function like this one. Confirm the data structure and permissions first, then add triggers and error handling. This makes it easier to identify whether a problem comes from the business logic, authorization, or trigger configuration.

Frequently asked questions

Do I need to install Google Apps Script?

No. Apps Script is available through Google Workspace editors such as Sheets and Docs. Open it from Extensions > Apps Script in a supported file.

Can I use the same script in another spreadsheet?

A bound script belongs to the file where it was created. To use the same code elsewhere, copy it into another file’s Apps Script project or create a reusable standalone project and explicitly identify the files it should access.

Does the script run automatically?

The onOpen function runs when the spreadsheet opens and adds the menu. The timestamp function does not run on a schedule; you start it by selecting the menu item. Scheduled or event-based automation requires a separately configured installable trigger.

Can I undo a script change?

Spreadsheet edits made by a script may be included in the spreadsheet’s normal edit history, but you should not rely on undo as your only recovery method. Test on a copy, validate ranges, and make backups before automating important data.

Next steps

You have now created a working bound Apps Script, authorized it, connected a menu item to a function, and tested a change in Google Sheets. The next useful exercise is to replace the timestamp action with a small task that saves you time every day—while keeping the same cycle: define the input, make one controlled change, test it, and inspect the execution history when something fails.

Google Apps Script authorization screen requesting access to a spreadsheet
Review the requested spreadsheet access before authorizing a script you understand.

About the author

Free Apps Script Team

This guide was created and reviewed for practical Google Workspace automation. Test scripts with sample data and review requested permissions before using them in production.

Continue learning

Related Apps Script guides