Google Apps Script
James Ferreira
Preface
If you are reading this book, there is a good chance you have heard of Google and its powerful office productivity suite, Google Apps. Google offers search, email, word processing, and hundreds of other cloud applications and services that are available to individuals but can scale all the way up to serve massive corporations and governments. As one of Googles most popular services, Google Apps offers some of the best online office products available; theyre an excellent example of web-based applications that outperform legacy desktop software.
This book is about Google Apps Script, which is a service that runs from Google Apps, like Sites and Documents. Google Apps Script is extremely powerful when automating many of the tasks required by day-to-day spreadsheet operations, but it also scales up to provide a complete application platform. If you are coming from a Microsoft Office environment, you can think of it as the macros for Google Docs, but unlike simple macros in MS Office, Google Apps Script has a mature online editor with all the features one would expect in a development platform. Unleash Google Scripts user interface capability and you can create entire data-driven websites and applications that run across most modern browsers, including mobile ones.
In addition to the integrated development environment (IDE), Google Apps Script comes with a manager for organizing scripts, built-in debugging, automatic code completion, timed event triggers, and automated revisioning, to name a few features. What really caught this authors attention was that everything is web-based. There is no need to download and configure a code editor or transport development files from computer to computer, wasting time resynchronizing files and reconnecting libraries. Simply sign into your Google account and start creating. Google Apps Scripts are written in JavaScript, so there is no need to compile the code, making application development very fast.
With its own set of libraries, Google Apps Script can interact with most of the services provided by Google, making it the Swiss Army knife behind the main products. Other application-building methods for accessing Google products, such as App Engine and the gData APIs (offered in many different languages), all require a place for you to develop and deploy your code. With Google Apps Script, you are building the code into the existing Google platform, and that provides a robust experience where your products inherit Googles legendary 99.9 percent availability. Because there is no need to have anything more than a basic Internet-connected browser, development on this platform is something anyone can get started with, without any up-front expense. Google Apps Script is not locked inside Google, where it can only talk to Google servers; rather, it can communicate through JDBC, JSON, and SOAP, and it has a urlFetch
method, making it very versatile when communicating across the Web.
At Google I/O 2012 a new feature called HTML Service was unveiled, giving Google Apps Script programmers the ability to build custom user interfaces that can run inside a spreadsheet window as a Google gadget or completely independently in a browser. Talk about earth-shattering: a cloud programing platform that can access just about any web-based service and has the ability to create AJAX-style web pages? That is noteworthy. To date, Google Apps Script is the only way to gain full access to Gmail at the message level, and more services are added every year.
This book will focus on teaching you how to build powerful web applications using Google Apps Script. It is laid out in sections that explain how the different parts of Google Apps Script work and puts all these together in a series of fully functional applications that you can put to work right away.
Who Should Read This Book
This book is perfect for anyone who wants to extend what can be done with Google Apps but is not ready to dive into the complicated world of the Google Web Toolkit and Java APIs. You dont have to be a webmaster or programmer to grasp the concepts in this book. Google Apps Script takes care of server configuration, gives you a place to save your projects, and allows you to start developing immediately. This book is approachable by anyone with basic coding skills and a fundamental understanding of JavaScript. If you have never used JavaScript, I recommend having a copy of Head First JavaScript (OReilly) close at hand to help you through concepts like variables, arrays, and objects. All the application examples have highly detailed explanations, so if you are a Google Apps power user, you should not have difficulty grasping the content in this book and writing incredible applications using Google Apps Script.
What You Will Need
You will need a web browser (I recommend Chrome) and any type of Google account. Thats it! Google Apps Script is a completely web-based solution that is free and ready for you to start programming today.
Conventions Used in This Book
The following typographical conventions are used in this book:
Italic Indicates new terms, URLs, email addresses, and file extensions. Constant width
Used for program listings, as well as within paragraphs to refer to program elements such as variable or function names, databases, data types, environment variables, statements, and keywords. Constant width bold
Shows commands or other text that should be typed literally by the user. Constant width italic
Shows text that should be replaced with user-supplied values or by values determined by context.
Tip
This element signifies a tip or suggestion.
Note
This element signifies a general note.
Warning
This element indicates a warning or caution.
Using Code Examples
At the end of each chapter you will find the full code used to create that chapters project. In addition, you may access all the files used to create this book in the books Drive folder.
This book is here to help you get your job done. In general, if example code is offered with this book, you may use it in your programs and documentation. You do not need to contact us for permission unless youre reproducing a significant portion of the code. For example, writing a program that uses several chunks of code from this book does not require permission. Selling or distributing a CD-ROM of examples from OReilly books does require permission. Answering a question by citing this book and quoting example code does not require permission. Incorporating a significant amount of example code from this book into your products documentation does require permission.
We appreciate, but do not require, attribution. An attribution usually includes the title, author, publisher, and ISBN. For example: Google Apps Script by James Ferreira (OReilly). Copyright 2014 James Ferreira, 978-1-491-94618-3.
If you feel your use of code examples falls outside fair use or the permission given above, feel free to contact us at .
Safari Books Online
Note
Safari Books Online is an on-demand digital library that delivers expert content in both book and video form from the worlds leading authors in technology and business.
Technology professionals, software developers, web designers, and business and creative professionals use Safari Books Online as their primary resource for research, problem solving, learning, and certification training.
Safari Books Online offers a range of product mixes and pricing programs for organizations, government agencies, and individuals. Subscribers have access to thousands of books, training videos, and prepublication manuscripts in one fully searchable database from publishers like OReilly Media, Prentice Hall Professional, Addison-Wesley Professional, Microsoft Press, Sams, Que, Peachpit Press, Focal Press, Cisco Press, John Wiley & Sons, Syngress, Morgan Kaufmann, IBM Redbooks, Packt, Adobe Press, FT Press, Apress, Manning, New Riders, McGraw-Hill, Jones & Bartlett, Course Technology, and dozens more. For more information about Safari Books Online, please visit us online.