Hello World in Google Apps Script

Hello World in Google Apps Script Featured Image

Welcome back to the Hello World in Every Language series. Once again, I get to chat about a code snippet that was shared by someone in the community, Arun Pattni. Thanks to them, we’re able to tackle Hello World in Google Apps Script, a scripting language that first appeared in 2009.

Table of Contents

Google Apps Script Background

According to Wikipedia, Google Apps Script is a scripting language for the G Suite which includes applications like Gmail, Google Drive, Google Calendar, etc. In other words, we’re dealing with a domain specific language.

In terms of features, Google Apps Script shares a likeness to JavaScript. As a result, the language is relatively easy to learn.

That said, there are some limitations. For instance, each script is executed in the cloud, so their are restrictions such as limiting access to various services.

In addition, working with date/time objects can be challenging as data may cross time zones during execution. As a result, developers have to be very deliberate in their scripts.

Overall, Google Apps Script appears to be a great tool for anyone looking to write add-ons for G Suite applications. Otherwise, you’ll probably never use it.

Hello World in Google Apps Script

At any rate, here’s the implementation of Hello World in Google Apps Script:

function helloWorld() {
  Logger.log("Hello, World!");
}

Unlike many languages, Google Apps Script code doesn’t need a main function. In fact, all we have to do is define a function. Google handles what we want to do with the script at runtime.

With that in mind, we can see that we’ve defined a helloWorld function with syntax similar to JavaScript. In other words, we have a function definition which encloses a code block with braces.

Inside the code block, we have our typical print call. In this case, we leverage the Logger to do our printing. Then we pass our “Hello, World!” string to the log function, and call it a day.

How to Run the Solution

If we want to run Hello World in Google Apps Script, we actually have to write our scripts using the Apps Script tool. From there, Google has some nice documentation for running them.

Alternatively, we can write scripts locally and upload them to Google Drive. At that point, we can connect the Google Apps Script tool to run our scripts. The link above has directions for that option as well.

If you know of other ways to run Google Apps Script code, let me know in the comments.

Sample Programs in Every Language

And, that’s it for Hello World in Google Apps Script. If you want to contribute to this language, consider forking the Sample Programs repository.

As always, thanks for stopping by and a special thanks to Arun Pattni for their contribution to the series. Every little bit helps!

While I have you here, consider sharing this article. I’m sure your friends will enjoy the series, and they might even want to contribute.

Series Navigation← Hello World in ALGOL 68Hello World in C* →
Advertisements

Leave a Comment

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