Google Apps Script Programming

I’ve been asked a few times to teacher a course for teachers on Google Apps Scripts. So I’m going to begin talking out the structure here until I can get a class together. I'll be working with Chrome to explore Scripts.

Scripts are instructions for a computer. The are read just as they are. they are a form of coding but not all coding or programming is scripting. Some languages have to be turned into specific computer read forms. This translation is called compiling. Scripts are interpreted just as they are. Most web interactions are done with scripts. Google Apps Script uses JavaScript. Typically javascript runs in the users computer. Google Apps Scripts run in the Google Cloud on the google servers. This makes the power of it consistent despite the user's machine. For a JavaScript course check out Codecacademy. I'll be using Google Apps Scripts, the Information on javascript can be helpful for a deeper under standing but not mandatory.


Let’s open Google Apps Scripts. Select One of the main GSuite Apps; Sheets, Docs, or Slides.  
On the top menu bar under Tools select Scripts
This opens a new tab with scripting tools to begin programing Forms opens slightly different from the three dots menu.

There’s a number of features within this tool but let’s keep it simple to begin. In Scripts we write functions. Let’s say you want a series of things done to come up with a particular result. We align code together in a function to be done in order to return some result. 

Usually we make up our own names for functions. The naming of things is usually where people get confused. Some names are reserved by the language creators to do things. To begin we’ll use a reserved function name in our code. JavaScript is case sensitive. So Function is different than function. And X is different than x. Mind your cases as you work. 

In the scripting area we are seeing:
function myFunction(){
}

We can remove this. Basically, it’s a prewritten function which does nothing. Let’s write our own. 
function:

function onOpen(){
  alert(“Hello World”);
}

This function uses a few reserved words.

  • function tells the browser that this is a series of code to be run in the order specified. 
  • onOpen is a reserved function name that binds the function to the document opening. 
  • alert is a reserved name for a function in JavaScript. 

The characters in our function also represent things.

  • The first () after onOpen are there to take in a value. 
  • The { is the start of our function. 
  • The } is the end of our function. 
  • Anything between { and } is part of our function,
  • alert uses () to take in a value. This is synonymous with the onOpen parentheses, (), which can take in a value. 
  • The “ “ are identifying what’s between them as words or what’s called a string datatype. 
  • The ; ends the line of code and tells to browser to move to the next line. 

For a function it must be structured in this way with <some name> being what you want to call your function and action code; being what you want you function to do. 
function <some name>(){
  action code;
  action code;
}

If you haven’t experimented with onOpen yet try it now. Close the document you were working on. Open your document back up from the drive. Give it a moment. Did you get an alert saying “Hello World”? If you did congratulations! If not compare your code to mine meticulously or copy and paste it. Remember it’s case sensitive. 

Let’s consider a usage for our pop-up. It’s great for quick disappearing messages. So directions would not be good here. Perhaps you want to give a shout out to a birthday, a high achiever, someone who did something special or unique. What about a quick reminder, “use the references”, “check your grammar”, “trip on Friday!”. Whatever you write is general to anyone who opens it right now. Can we get specific for individuals? It’s possible. For now let’s celebrate that you just wrote some code that you can use in class right away.

Congratulations!


Any copy of a Doc, Sheet, Slides, or Form will contain the script. If you write some great code you want to use in another file you can copy the code and past it to the new file’s scripting area or copy the file. 

3 comments:

  1. I was able to take a script by Eric Curts www.ControlAltAchieve.com and display three columns of random things in Google Spreadsheet, I added a button to pick another set. I use this in my adult English language class with (subject, verb, time phrase) to get students to make a statement or question. I would like to display it in a prettier way - without all the spreadsheet tools etc. Do you know if the data from the spreadsheet can be displayed in a Site or Doc or Slide and have a button to refresh? I will be glad to share the spreadsheet with you.

    ReplyDelete
  2. Hey, it’s you, i need help writing an essay ! We have a dedicated support team who work round the clock, ready to provide speedy assistance to all customers. Whatever issue you are experiencing, feel free to contact support via the live chat feature, and they will respond and sort out your issue immediately.

    ReplyDelete

Social Emotional Well-Being During Online Teaching and Learning

The world is a bit nutty right now because of the COVID-19 pandemic. Schools are switching to online learning and parents are working from...