Guide to coding apps script
Increase the power of your favorite Google apps — like Calendar, Docs, Drive, Gmail, Sheets, and Slides.
Google Apps Script Home
Apps Script is a rapid application development platform that makes it fast and easy to create business applications that integrate with G Suite.
Apps Script Permissions
A standalone script is any script that is not bound to a Google Sheets, Docs, Slides, or Forms file or Google Sites. These scripts appear among your files in Google Drive.
Creating a standalone script
The easiest way to create a standalone script is to visit script.google.com and at the top left, click addNew project.
You can also create standalone scripts from Google Drive after a few steps of setup:
Go to Google Drive and click New > More > Connect more apps.
When the “Connect apps to Drive” window appears, type “script” into the search box and press Enter.
Click Connect next to the listing for Google Apps Script.
Now that you’ve connected the app, you can create a script by selecting New > More > Google Apps Script.
A script is bound to a Google Sheets, Docs, Slides, or Forms file if it was created from that document rather than as a standalone script. The file a bound script is attached to is referred to as a “container”. Bound scripts generally behave like standalone scripts except that they do not appear in Google Drive, they cannot be detached from the file they are bound to, and they gain a few special privileges over the parent file.
Note that scripts can also be bound to Google Sites, but these scripts are almost always deployed as web apps. Scripts bound to Sheets, Docs, Slides, or Forms can also become web apps, although this is uncommon.
Creating a bound script
To create a bound script, open a Google Sheets, Docs, Slides, or Forms file, then select Tools > Script editor. To reopen the script in the future, do the same thing. Because bound scripts do not appear in Google Drive, that menu is the only way to find or open the script.
Bound scripts can call a few methods that standalone scripts cannot:
getActiveSpreadsheet(), getActiveDocument(), and getActiveForm() allow bound scripts to refer to their parent file without referring to the file’s ID.
getUi lets bound scripts access the user interface for their parent file to add custom menus, dialogs, and sidebars.
In Google Sheets, getActiveSheet(), getActiveRange(), and getActiveCell() let the script determine the user’s current sheet, selected range of cells, or selected individual cell. setActiveSheet(sheet) and setActiveRange(range) let the script change those selections.
In Google Docs, getCursor() and getSelection() let the script determine the position of the user’s cursor or selected text. setCursor(position) and setSelection(range) let the script change those locations.