Google Apps Script Basic Tutorial

Posted by Darwin Biler on December 16, 2012

If you are using Google Drive (Google Docs before), you might be interested to the fact that you can do some form of automation (mail merge for example) on Google Docs like how MS Office's Visual Basic for Application do some sort of "scripting" capability in all of it's Office Application.

That functionality as a whole is offered to what Google called as Google Apps Script. It basically provides an end-user to do some scripting and execute it on Google's server making it robust and handy since everything is stored in the cloud, unlike MS Office that you have to send the Office Doc itself and the user must download it to its hard disk, must have a MS Office installed.

Google App Script otherwise is very portable since you just need the link to that Google Doc, set some permission and the user dont need to install anything on his computer in able to run your script (a browser is all he need).

I will show you some "Hello World" tutorial to get you started with Google Apps Script, but this doesn't mean this technology is just about Office docs automation - there is a wide range of services and functionality that you can do with Google Apps Script. We will just tackle the very basics of it so that you can have a better grip of how this technology can change the way how you use Google Docs.

First, go to https://drive.google.com. Of Course you need to have a Google Account for you to do all this things so make sure you are logged in to your Google Account.

Next, create a new Spreadsheet document
gas1

Name the spreadsheet with something that you are able to remember (it could be anything that you want). Then make sure to save it (you dont have to enter any data in the cells).
gas2

Now, open that Spreadsheet document that you had just created.

gas3

Go to Script Editor

gas4

That should open another tab, which looks like an IDE (Integrated Environment Development) where you can write codes, create projects etc. There will be a default project/ file (Code.gs) which is provided by Google to you, but basically you can create more projects code files. For the purpose of this tutorial, we will edit the default and drop some lines of codes.

gas5
Clear the contents of Code.gs and put the ff. code:

function onOpen()
{
  Browser.msgBox("Hello World");
}

The codes instructs the Spreadsheet to execute the codes enclosed in the parentheses when the Spreadsheet is "opened" by the user. In our case, It will open a "Message Box" on the browser.

gas6
So that's it, you just had made your first Google Apps Script!

Note that there are much wider use-cases for this aside from scripting a document, among others were:

  • Build stand-alone apps that can be served like a regular website
  • Search and Read the Inbox of your Gmail account
  • Do mashups by aggregating different contents from different sources like RSS feed and serve it via Google Apps Script
  • and many more...

Watch the following video to know more about Google Apps Script:

Or you can go directly to http://www.google.com/script/start/


Did you find this useful?

I'm always happy to help! You can show your support and appreciation by Buying me a coffee (I love coffee!).