Skip to Main Content
University of York Library
Library Subject Guides

Coding: a Practical Guide

Google Apps Script

Google Apps Script

Want the Google apps to do more?

Google Apps Script is a coding language based on JavaScript that allows you to extend and manipulate Google apps like Drive, Sheets, Docs, and Gmail.

What is Apps Script?

Apps Script is a coding language designed so you can do more with Google applications like Drive, Docs, Sheets, Calendar, Gmail, and more. It is based on JavaScript and runs in the cloud rather than on your device.

It is helpful for automating things you might do in Google apps or finding creative solutions to problems.

What is JavaScript?

JavaScript is a coding language for web development, which is a fancy way of saying making web pages. It tends to be used to add interactivity and functionality to web pages, which are built using HTML and CSS to give them structure and style.

JavaScript is a scripting language, which means it creates scripts that can be run when particular 'events' or 'triggers' tell the code to run. Apps Script works the same, but instead of being based on a web page, it is based on Google Drive and can be 'bound' to particular Google files like Sheets or just exist on Google Drive as an 'unbound' script file.

It is useful to know some JavaScript concepts to work with Apps Script, as there's some features you'll need to use with Apps Script. Check out our JavaScript and jQuery page for introductory resources on JavaScript.

Apps Script works by accessing different 'apps' within your code so that you can work with Google applications and their respective features. For example, you use the SpreadsheetApp to work with features of spreadsheets and the DriveApp to work with features of Google Drive.

The basics of Apps Script

Apps Script has similar fundamental features to other coding languages. You tend to start learning Apps Script by learning about variables and data types and looking into how to write Apps Script in the Script Editor. Next, you tend to explore one of the 'apps' built in to Apps Script to work with a specific Google tool, for example the SpreadsheetApp to work with Google Sheets.

Variables in Apps Script

The basic terminology of coding applies to Apps Script (check out the Introduction to coding page if you've not already and you're new to coding), so you'll find things like variables, comments, conditions, and loops are all features. The first thing you tend to learn how to do is to create a variable, which is a value you've saved with a name so you can access it again in your code.


In Apps Script, a variable can contain not only individual values and lists of values (called arrays), but also whole spreadsheets or documents.

To create a variable, you must tell Apps Script it is a new variable using the keyword var and then give it a name. You then assign it a value using the equals sign =, which in coding is the assignment operator, and enter the value of the variable after the equals sign. So you might have something like:

var startingValue = 0;

As the name 'variable' suggests, the value of a variable can be changed, so

startingValue = 1;

would change the value of startingValue to 1.

You can also write a line of code that has an output and have that after the equals sign when creating a variable, so you could for example create a variable that is assigned the value of the outcome of a calculation, or which uses one of the Apps Script apps to store a spreadsheet in it, like:

var ss = SpreadsheetApp.getActiveSpreadsheet();

When you're first learning Apps Script, it can be helpful to try out creating different kinds of variables and using the Logger to check their value by viewing the Execution Log, so you know you're doing it correctly:


Data types in Apps Script

Data types in coding tell the computer what kind of data is stored in the variable, which then allows different kinds of things to be done with that data. For example, if you add together two numbers, you'll get a numerical answer, but if you add together two text strings, you will concatenate them (join them together).

Some of the key data types you'll use in Apps Script are: numbers; strings (a collection of characters that can include text, numbers, punctuation and spaces); and arrays (a list of values stored together, which can contain other data types including arrays themselves).

To create these data types, you use particular syntax. For example, numbers are entered without punctuation, but strings need to be surrounded by single or double quotes, and arrays must be surrounded by square brackets and each item in an array must be separated by a comma.

var number = 7;
var text = "Apps Script";
var things = [7, "Apps Script", 998.87];

In Apps Script (and JavaScript) you can change the data type of a value just by assigning it a new value.


As we've already mentioned, arrays contain multiple items in one variable, and can contain different data types including other arrays. In Apps Script, if you get the values from a spreadsheet, for example, these will be in the array data type, so it is useful to know how to use and navigate arrays. We'll take a look at how to access specific values from within an array.

If you have a single array, for example:

var session = ["Intro to Google", "Online", 50];

you can access the individual values using index numbers within square brackets


would give the output of Online.

This may seem counterintuitive, because "Online" is the second item in the array, but index numbers in arrays in coding start from 0, so the first item is index number 0, the second item is index number 1, and so on. This can catch you out, so it's always worth using the Logger.log() command to check what variable you have when you're first trying to access a particular value in an array.

If you have one or more arrays stored within an array, like

var courseList = [["Intro to Google", "Online", 50], ["More Drive tips", "Face to face", 15], ["Using Google Docs more", "Online", 75]];

then you have to use two index numbers to access individual values, and a single index number to access one of the sub-arrays. We often call this kind of array a two-dimensional (2D) array and it is often used in Apps Script to represent individual rows in a spreadsheet as the sub-arrays and then the main array is the whole spreadsheet. For example, getting one sub-array (which might be one line of a spreadsheet):


would ouput ["Using Google Docs more", "Online", 75] and


would output Using Google Docs more.

If you want to get your head round arrays a bit more, you can take a look at our Exercises with arrays.

Bound and unbound scripts and the Apps Script editor

When creating a new Apps Script project, you have to decide if it will be bound to another Google Drive file (like a spreadsheet) and accessible via the Apps Script editor or unbound, which means that the Apps Script project file itself will sit on Google Drive. In most cases, Apps Script projects bound to a particular file are most useful, as typically there will be a spreadsheet of data or form responses you want the script to work with and it makes sense to keep these connected.

To create a bound Apps Script project, you create or open a Google Sheets file, then go to Extensions > Apps Script and the Apps Script editor will open. You can then name your project, and rename the default "" file to something more specific. Typically you'll also rename the default function myFunction with a more descriptive name for your code too.

Our Essential Apps Script booklet goes over these concepts and then explores some of the useful functionality of Apps Script for working with spreadsheets and documents, creating repetition and conditions in your Apps Script code, sending emails, and working with forms and triggering code to run.

How do I learn Apps Script?

Apps Script is a good beginner coding language to learn if you work with Google tools, as it allows you to automate processes and do useful things without needing to learn everything about Apps Script first. The different Google apps have different Apps Script commands you can use for them, meaning you can focus on what you can do with e.g. Google Sheets or Google Drive as is relevant to you, and learn more as you want to extend your Apps Script projects.

The first thing you'll need to know about is the Google applications themselves, so we'd recommend you make sure you're familiar with using Google Drive and Docs especially, including how sharing works.

If you're a member of staff at the University of York, you can book onto a five-week Essential Apps Script course on the Learning Management System. The course starts from the basics of Apps Script and uses projects to develop your skills.

Google has created a whole site for Apps Script, which includes some guides and basics and, mostly importantly, a full reference for all of the commands you can use in Apps Script. It is a great place to find answers and learn more about Apps Script.

The guides they have start from an overview of Apps Script and then contain some quick start examples and further tutorials. If you're learning Apps Script this way, you'll also want to look at information on JavaScript separately to understand some of the other things you'll need to do to use Apps Script, like variables, loops, and if conditions.

Once you start learning Apps Script (or, indeed, any coding language), it's good to explore other people's code to see what else you can be doing or other methods for doing things you've been trying. You can look on sites like Stack Overflow to ask and answer questions about coding, or you can look at specific sites created to share code in particular languages.

Planning an Apps Script project

So, what can you do with Apps Script? How do you go about planning an Apps Script project?

If you've used Google Workspace apps, you've probably got some ideas about what you wish they could do or have processes it would be good to automate. You might want to be able to create a lot of files or folders in one go, automate things that happen from a form submission, or extend Google Sheets.

One important thing to consider is scale. For most users, Apps Script is very good for small scale solutions, but if your project would either be used more widely than just you, or would be used for larger scale or business critical processes, you might need to take extra things into consideration. If you're at the University of York, get in touch with IT via to discuss any Apps Script projects you might be looking into doing and get advice.

For more on using Google apps and what they can already do, see our Google Workspace guidance:

If you're at the University, we've created some useful tools based on Apps Script, that can be used without any coding knowledge. Check there's not already a tool out there for what you're looking to do:

What kinds of things can you do with Apps Script?

If you're learning Apps Script and want some inspiration for what you could do, here's some things that are possible with Apps Script (caution: some of these might be trickier than others to create!):

  • Bulk create Google Drive folders with specific naming conventions
  • Bulk rename Google Drive files or folders.
  • Create Google Docs from data contained in Google Sheets and store in a particular Drive location.
  • Automatically create Google Docs from a Google Form submission.
  • Send personalised emails from data contained in a Google Sheet (and add links to particular Drive files).
  • Create Calendar events from data in a Google Sheet.
  • Bulk create PDFs of Google Docs.
  • Monitor Google Sheets edits.


If you want to have a go at writing some Apps Script, try the walkthrough below, which is designed to get you creating your own Apps Script code to 'read' a value from a spreadsheet cell.