Teacher Tech blog with Alice Keeler

Paperless Is Not a Pedagogy

Alice Keeler

Getting Started to Learn Google Apps Script

Are you wanting to be Getting Started to Learn Google Apps Script? The good news is it isn't as hard as you think it is. Coding Google Apps Script is really handy since you already use Google Docs, Sheets, and Slides ... but you want it to do more.
Getting Started to Learn Google Apps Script

Google Apps Script is a powerful tool that allows users to automate and extend the functionality of Google Workspace (formerly known as G Suite) products such as Google Sheets, Docs, and Forms. With Google Apps Script, you can create custom applications for Google Docs, Sheets, Slides, Forms, etc… If you have ever wondered “Why doesn’t Google Docs do this…” then learning Google Apps Script is for you. I started by using #ChatGPT to see how it did in explaining it and then I expanded on it. So here is Getting Started to Learn Google Apps Script:

Want More Help with This? Become a Premium Member


If you’re new to Google Apps Script, getting started can seem overwhelming. However, with a little bit of guidance and some basic knowledge of JavaScript (the programming language used in Google Apps Script), you’ll be well on your way to creating your own custom scripts and macros.

1. First, navigate to the Google Apps Script website (https://script.google.com/) and sign in with your Google account.

2. Once you’re signed in, you can create a new script by clicking on the “New Script” button. This will open up the script editor, where you can start writing your code.

To Getting Started to Learn Google Apps Script you want to put your code between the curly braces within the function.

3. If you’re new to JavaScript, it’s important to familiarize yourself with the basics. There are many resources available online to help you learn JavaScript, such as Codecademy and W3Schools.

Specific Methods for Google Apps Script

4. Google Apps Script has its own set of built-in functions and objects that you can use to interact with Google Workspace products. You can find a list of these functions and objects in the Google Apps Script documentation (https://developers.google.com/apps-script/). Google searching for the methods is a great way to locate what you need in the documentation.

5. To get a better understanding of how Google Apps Script works, it’s a good idea to start experimenting with some of the sample scripts provided in the documentation. These samples will give you a good idea of how to structure your code and how to use different functions and objects.

6. Once you feel comfortable with the basics, try experimenting with your own scripts and macros. For example, you could create a script that automatically organizes your emails in a Google Sheet, or a macro that formats text in a Google Doc.

Publish Your Add-on

7. You can informally publish your Add-on by sharing the script or the Google Docs file with friends.

8. As you become more proficient in Google Apps Script, consider sharing your scripts and macros with others by publishing them to the Google Workspace Marketplace. This is a great way to share your knowledge and help others automate their own tasks.

Google Apps Script is a powerful tool that can save you a lot of time and effort. By following these steps and practicing with sample scripts, you’ll be well on your way to becoming a Google Apps Script expert.

Sample Starter Code

You can choose to have a bounded or unbounded script. I usually choose bounded, which means that it is part of a particular Google Docs, Sheets, Slides, etc…

Open a new Google Doc (or Sheets or Slides) and use the Extensions menu to choose “Apps Script.” This will show you the same coding IDE as creating an unbounded script at script.google.com.

Sample Add-on

Click on the button below to create a sample Google Doc. Go to the Extensions menu and view the bounded script that is part of the Google Doc. Notice that I was able to share this code with you by simply sharing the Google Doc with you. Bounded scripts are much easier to informally distribute to people who do not have coding experience.

Coding the IDE

  1. The coding IDE presents you with a default function called myFunction(). I would recommend you rename this function to something more meaningful. The function name has to be ONE word, no spaces.
  2. You can add notes to your code with comments. Start a comment with 2 slashes. This allows you to explain what you are trying to do in the code. This is not only helpful to you, but allows others who are looking at your code to understand what you are trying to do.
  3. You can name your variables with const or let or var. Create a variable that describes the document you are coding. In this case, I am coding Google Docs so DocumentApp is the object I need to use. End your line of code with a semicolon.

Using Variables

You want to name lines of code so that they are reusable. You name them with a variable. Use const if the value is constantly that value and should never change. Let variables should also not be reused, however they can be reused in a block such as a loop. Var variables can be redefined so be careful and use sparingly.

After creating a variable to define doc as the current Google Doc, type that variable on another line and press period.

Pressing period after a variable will produce a multiple choice list.

screenshot of the Apps Script coding IDE. Added const body = doc.get and this produces a multiple choice list of options.

For Google Docs you can code the overall document such as naming the document or you can code the text in the document. You need to consider if the text goes in the header, the footer, or the main body of the document.

After naming a variable for the document you will need a variable for the body of the document. Using this variable you can press period and modify the text in the document.

code sample labeled one. Two is save and 3 is run. 

function myFunction() {
  //Your code goes here
  //this is a comment it starts with two slashes to indicate this is not code.

  //Typically you start with the Google App you are coding. In this case it is DocumentApp. You would use SlidesApp or SpreadsheetApp if you were coding those file types. 
  const doc = DocumentApp.getActiveDocument();

  const body = doc.getBody();
  body.appendParagraph('This is Alice')

Save and Run

After giving a few lines of instructions be sure to save and run the code to test it out!

Getting Started to Learn Google Apps Script

Getting started to learn Google Apps Script is easy and straightforward. It is a powerful tool that allows you to automate and customize various Google products such as Google Sheets, Google Docs, and Google Forms. With a little bit of programming knowledge, you can start creating your own scripts to make your workflow more efficient.

One of the best ways to get started to learn Google Apps Script is to explore the vast resources available online. From tutorials, to videos, to forums, there is a wealth of information available to help you learn the basics. Additionally, Google offers a comprehensive documentation on how to use the Google Apps Script platform.

Another great way to get started to learn Google Apps Script is to find a project that you are interested in and start experimenting. For example, you can create a script that automatically organizes your Gmail inbox or generates reports from your Google Sheets data. The possibilities are endless and the more you use it, the more you will discover its potential. With Google Apps Script you can save time, automate tasks and make your workflow more efficient.

© 2024 All Rights Reserved.