Back to Top

Getting Started with Google Apps Script

GETTING STARTED WITH GOOGLE APPS SCRIPT

Google Apps Script developed by ​Romain Vialard which appeared in 2009.Google Apps Script is a JavaScript-based language which can be used for automatically formatted customized e-mail messages ,Google document file for automatic operation.Google Apps Script is a language for the task automation with the online application using the classic JavaScript.

This article explains you about what a Google Apps Script and how you can use it. After reading this article, you will get a glimpse of the boundless possibilities of Google Apps Script. I must say Google Apps Script is convenient and very easy to understand.

What is GAS – Google Apps Script?

The Google Apps Script is written in JavaScript language and hosted on Google’s servers. Google Apps Script is a kind of Google project which provides a development environment that is integrated into Google Drive with the ability to run and debug.

The purpose of Google Apps Script is to provide an automated system that will benefit both Google applications and other third-party programs. Google Apps Script is the script which can be used to create custom forms, automatic repetitive tasks and linked to a variety of Google products, such as to select one or more newsletter to send an email or a calendar event. You can easily customize an existing Google products including Gmail, Google Docs, Google Drive, Google Contacts, Calendar, Maps and Google Analytics using Google Apps Script.

Here is the main points of Google Apps Script:

  • Google Apps Script is a JavaScript Cloud Scripting language to automate tasks.
  • You can use editor in a browser & managed in cloud computing implementation. No installation or setup required. You can store,share and versioning files.
  • JavaScript runtime in the cloud ( compliant, debuggable, and performant )
  • Set of APIs and hooks to Google products (extend and enhance, built in security, distribution mechanisms 2 11 Google apps, 1 platform in the cloud.

What Google Apps Script do?

  • Using Google Apps Script, You can add a custom menu or side menu.
  • You can write custom google sheets function using the Google Apps Script.
  • You can publish web applications alone or with embedded google sites
  • Also, You can interact with other services Google, contains AdSense, Analytics, Calendar, Drive, Gmail, Maps.
  • Last but not the least,automate your task with few lines of code.

Getting Started with Google Apps Script (GAS)

Google Apps Script is the standalone script on https://script.google.com.Sign in Google Drive and creates a new spreadsheet(Google Sheets). Here are the menu steps.

Open the created table and select the top menu Tools > Script Editor for Spreadsheet/App-bound script and it will redirect to https://script.google.com and you can to write a script.

Next, When you run the script, Do take care of the Authorization Step.Below confirmation box will appear first.

Google-apps-script-autherization

After you review permission, click on allow and approve the script to run.

What Google Apps Script Provide?

Google Apps Script will provide the following:

  1. You can use the JavaScript APIs for easy interaction between different Google product.
  2. The development using Google Apps Script is faster with standard JavaScript. You can use online Web Script Editor of Google or desktop development Editor.
  3. Also, Google Apps Script provides basic collaboration and sharing support.
  4. Google Apps Script execute scripts or hosted in the cloud on Google.
  5. Easy development and maintenance work.
  6. You can use OAuth implement standard security measures in Google Apps Script.

Standalone Script Example function

Let’s understand the Example of Google Apps Script. After Log into Google Drive and create a new spreadsheet when Go to Script Editor, You will get the new page opens with a Google script IDE and this is where the fun begins. Here is the screenshot of the screen.

Google-apps-script-standalone-editor

You have to copy paste following script in the “script editor”, which you will find at the menu bar of the spreadsheet.

When this function will run, send the email to your id with attached spreadsheet link. You can automate your task with Google Apps Script.

Triggers in Google Apps Script

A trigger is a type of script resource that listens for a particular event and executes a function when that event fires.

There are few types of triggers available in the Google Apps Script:

Simple triggers – Simple triggers are a set of reserved functions built into Google Apps Script.Some Specially named built-in functions that are specific to spreadsheets.

  1. onEdit – Changing the document (which can be made using IFTTT)
  2. onOpen – The opening of the document
  3. onInstall – Installable triggers

After you write the above function in the Google Apps Script,you need to create a trigger which will run the script. To create a trigger, Go to the top menu > “Resources”. In that click on “Current Project’s Triggers.You will get the popup to create the new trigger.

google-apps-script-triggers

Here you can set the execution time of project:

  • The specific day and hour
  • Every week / day / month
  • Every n minutes / hours / days

After all the setup in the trigger section,It’s time to test the script so try to run the script.

Spreadsheet / App Bound Script Example

The bound​ script is a kind of script bound to a Google Sheets, Docs, or Forms file if it was created from that document rather than as a standalone script.

Bound scripts can call a few methods getActiveSpreadsheet(), getActiveDocument(), and getActiveForm() allow bound scripts to refer to their parent file without referring to the file’s ID.

getUi() function allows the user interface for their parent file to add custom menus, dialogs, and sidebars for bound scripts.

In Google Sheets, You can use the methods like getActiveSheet(), getActiveRange(), and getActiveCell() which determine the user’s current sheet, selected range of cells, or selected individual cell respectively .setActiveSheet(sheet) and setActiveRange(range) is the script used to change those selections.

In Google Docs, Methods getCursor() and getSelection() used to determine the position of the user’s cursor or selected text and setCursor(position) and setSelection(range) l functions are used to set the script change those locations.

Thank you for reading to the end and Special thanks to all the people who made and released these awesome resources for free.All you need to start experiments using the official documentation and reference.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Most Popular Posts

How to use Web service in WordPress?

Posted on 10 years ago

Bhumi