Got 5 mins? Help us improve Apps Script documentation by taking a quick online study.

Overview of Google Apps Script

Google Apps Script is a rapid application development platform that makes it fast and easy to create business applications that integrate with Google Workspace. You write code in modern JavaScript and have access to built-in libraries for favorite Google Workspace applications like Gmail, Calendar, Drive, and more. There's nothing to install—we give you a code editor right in your browser, and your scripts run on Google's servers.

If you're new to JavaScript, Codecademy offers a number of JavaScript courses. (Note that these courses weren't developed by and aren't associated with Google.)

What can Apps Script do?

Apps Script is versatile. Among other things, you can:

  • Add custom menus, dialogs, and sidebars to Google Docs, Sheets, and Forms.
  • Write custom functions and macros for Google Sheets.
  • Publish web apps — either standalone or embedded in Google Sites.
  • Interact with other Google services, including AdSense, Analytics, Calendar, Drive, Gmail, and Maps.
  • Build add-ons to extend Google Docs, Sheets, Slides, and Forms, and publish them to the Add-on store.
  • Convert an Android app into an Android add-on so that it can exchange data with a user's Google Doc or Sheet on a mobile device.
  • Streamline Google Chat workflows by building a chat bot.

Your first script

Build and run a simple standalone script that creates a Google Doc and emails you a link to it.

Set it up

To build the script, follow the steps below.

New editor

  1. Sign in to your Google Account.
  2. To open the script editor, go to script.google.com. If this is the first time you've been to script.google.com, click View Dashboard.
  3. At the top left, click New project.
  4. Delete any code in the script editor and paste in the code below.

    templates/standalone/helloWorld.gs
    /**
     * Creates a Google Doc and sends an email to the current user with a link to the doc.
     */
    function createAndSendDocument() {
      // Create a new Google Doc named 'Hello, world!'
      var doc = DocumentApp.create('Hello, world!');
    
      // Access the body of the document, then add a paragraph.
      doc.getBody().appendParagraph('This document was created by Google Apps Script.');
    
      // Get the URL of the document.
      var url = doc.getUrl();
    
      // Get the email address of the active user - that's you.
      var email = Session.getActiveUser().getEmail();
    
      // Get the name of the document to use as an email subject line.
      var subject = doc.getName();
    
      // Append a new string to the "url" variable to use as an email body.
      var body = 'Link to your doc: ' + url;
    
      // Send yourself an email with a link to the document.
      GmailApp.sendEmail(email, subject, body);
    }
  5. At the top, click Save .

  6. At the top left, click Untitled project.

  7. Enter a name for your script and click Rename.

Legacy editor

  1. Sign in to your Google Account.
  2. To open the script editor, go to script.google.com. If this is the first time you've been to script.google.com, click View Dashboard.
  3. Delete any code in the script editor and paste in the code below.

    templates/standalone/helloWorld.gs
    /**
     * Creates a Google Doc and sends an email to the current user with a link to the doc.
     */
    function createAndSendDocument() {
      // Create a new Google Doc named 'Hello, world!'
      var doc = DocumentApp.create('Hello, world!');
    
      // Access the body of the document, then add a paragraph.
      doc.getBody().appendParagraph('This document was created by Google Apps Script.');
    
      // Get the URL of the document.
      var url = doc.getUrl();
    
      // Get the email address of the active user - that's you.
      var email = Session.getActiveUser().getEmail();
    
      // Get the name of the document to use as an email subject line.
      var subject = doc.getName();
    
      // Append a new string to the "url" variable to use as an email body.
      var body = 'Link to your doc: ' + url;
    
      // Send yourself an email with a link to the document.
      GmailApp.sendEmail(email, subject, body);
    }
  4. Select the menu item File > Save. Name your new script and click OK.

Try it out

To execute the script, follow the steps below.

New editor

  1. At the top of the editor, click Run.
  2. In the first dialog box that appears, click Review permissions. In the second dialog box, review the permissions your script uses and click Allow.
  3. When the script execution completes, check your Gmail inbox for the new email.
  4. Open the email and click the link to open the Google Doc you created.

Legacy editor

  1. To execute the script, either click run ▶ or select the menu item Run > createAndSendDocument.
  2. A dialog box will appear and tell you that the script requires authorization. Click Continue. A second dialog box will then request authorization for specific Google services. Read the notice carefully, then click Allow.
  3. A yellow bar at the top of the script editor will indicate when the script is running. When the yellow bar disappears, the script has finished.
  4. Check your Gmail inbox for the new email, then click the link to open the Google Doc you created.
  5. Open your Google Drive. You'll see that both the script and the document are stored there.

Learn more

To continue learning about Apps Script, take a look at the following resources: