Teacher Tech blog with Alice Keeler

Paperless Is Not a Pedagogy

Alice Keeler

More Google Apps Script Coding

more google apps script
More Google Apps Script Coding

more google apps script

Code More Google Apps Script

Google Apps Script allows you to code Google Apps such as Docs, Sheets, Slides, Forms, Maps, Gmail, and more. If you’ve ever wondered “why doesn’t G Suite do…” you probably can if you code it yourself! Google Apps Script is based on JavaScript and is a lot easier than you think!

Go Slow Workshops

alicekeeler.com/goslow

These coding workshops are NOT about teaching students to code. It is for YOU to learn how to code. For YOU to try to be more efficient at doing teacher tasks, especially boring repetitive tasks. Can’t robots do this for me? MAYBE! Go Slow workshops are 6 weeks long, are facilitated in Google Classroom, and weekly asynchronous (no specific time to be online).

2 Workshops May 14th, 2018

Coding for Noobs: Requirements for this workshop is you know how to copy and paste and you’ve thought to yourself “I might like to learn to code.” You will NOT be a ninja at the end of this workshop. It is only 6 weeks and it’s Go Slow. The goal is for you to feel that coding is not that scary and that you will feel like you have a direction to get you started.

More Coding for Noobs: If you’ve dabbled in Google Apps Script I’m starting a new workshop for going beyond the basics. This is still for teachers new to Google Apps Script coding. This is the follow up to my Coding Google Apps Script for Noobs online Go Slow workshop.

Try Some Code

Your first step is to know what does it mean to code Google Apps Script? If you’ve used any of my Add-on scripts, I coded them with Google Apps Script! My favorite is TemplateTab (https://alicekeeler.com/templatetab). Give TemplateTab a try so you can see one idea for how coding can make teaching easier!

YouTube video

Now You Code

Step 1: Create a Google Doc

docs.google.com/create

Give your Google Doc a name! Don’t let it stay “Untitled Document.”

Step 2: Tools Menu

Select the “Script editor” under the Tools menu.
script editor

Step 3: Cursor Between the Curly Braces

A function runs a set of code. You might have multiple functions to do multiple features. Let’s just do ONE!
function myFunction

Step 4: What App Are You Using?

Most often the first line of code is WHAT APP ARE YOU USING? In this case, the Google App is DocumentApp (as opposed to SpreadsheetApp, SlidesApp, FormApp, etc…)

Type

var doc = DocumentApp

DocumentApp
(capitalization and spelling matters!)

Step 5: Press the Period Key

We stack commands. Press the period to join it with what you want it to do with the app. Read the list! Some of it you know what it is. If you don’t know what it is, you don’t need it 🙂 Choose getActiveDocument(). Select it from the multiple choice! Spelling and capitalization matter so it’s safer to pick from the list!
getActiveDocument

Step 6: SEMICOLON!

End your lines of code with a semicolon!
Do not forget the semicolon

Step 7: Build on the previous line!

New line of code! Press enter. We defined a variable var doc = so we can easily REUSE it!
2nd line of code

Step 8: Press That Period Baby!

Build on what you want to do with that active document. Type doc and press period! Read the multiple choice list!!
doc and press period

Step 9: Do Something to that Doc

A few of the multiple choice items are pretty easy. One thing to know is any text you type (not code) you need to put in single quotes. Do not forget to end each line of code with a semicolon! Do one or multiple ones. If you decide to try out more than one they need to be on their own line. Start each line with your variable doc and press the period!
try some code!

A few easy methods to join with your doc variable is addEditor(), addViewer(), or setName(). Notice for addEditor(’email’) and addViewer(’email’) you need to put a valid email address within the parenthesis. Very important, the email addresses must be within single quotations. For setName(‘name’) you can rename the doc to whatever you want, but again you need the name to be in single quotations.

Step 10: Save

Control S to save or use the save icon in the toolbar. This will prompt you to save the code. Save it as anything you want.

Step 11: Run Your Code

Click on the sideways triangle in the toolbar to choose “Run.” You will need to authorize your code.
Run your code

Check it! Did the document rename, is it shared with who you thought you were sharing it with?

Want MORE?

For some of the methods in the multiple choice list you need to build upon them further. Type another period to add additional functionality.

GetBody

When you “Get” something with code nothing happens! Okay you got it… now what do you DO with it? This requires an additional command. Create a new line of code. Type your variable doc and press period. Choose getBody(). Now press the period again to tell the code what to do with the body of the document.
body.getBody()

So, what DO you want to Do with the body of the document? You have some choices!
get Body and do something with it

Append

Appending (add to the bottom) is the easiest to choose. Try ONE (or more than one). Do not forget the semicolon at the end of each line of code. If you append a paragraph do not forget to put your paragraph text in single quotes. Save and run your code, see what happens!
append some things

Have fun playing with some code! Do not get discouraged if it does not work. I know this sounds crazy but it is better when it does not work. The fist pumps are bigger when you have to figure it out a little. Double check spelling, capitalization, do you have a semicolon, do you have single quotes around your text? Notice that your text strings turn RED when you put single quotes around them. This is super helpful to find typos!

The Code

And if you want to copy and paste, here is the code.

function myFunction() {
var doc = DocumentApp.getActiveDocument();
doc.addEditor(‘thealicekeeler@gmail.com’);
doc.addViewer(‘ss2@fresnoteach.org’);
doc.setName(‘El Chupacabra’);

doc.getBody().appendHorizontalRule();
doc.getBody().appendParagraph(‘I am adding a paragraph’);
doc.getBody().appendParagraph(‘Two paragraphs are more fun’);
doc.getBody().insertHorizontalRule(1);
doc.getBody().appendPageBreak();
doc.getBody().appendParagraph(‘This is on a new page’);
}

© 2024 All Rights Reserved.

💥 FREE OTIS WORKSHOP

Join Alice Keeler, Thursday Mar 28th or register to gain access to the recording.
Create a free OTIS account.

Join Alice Keeler for this session for a way to create dynamic and interactive digital lessons. The Desmos platform is completely free and allows for any topic to be created or customized.

Exit this pop up by pressing escape or clicking anywhere off the pop up.