• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
Intro to Google Apps Script

Intro to Google Apps Script



An introduction to Google Apps Script. It is a technology that allows you to write in JavaScript and HTML, and execute the code within Google's Cloud. It revolves around the Google Account.

An introduction to Google Apps Script. It is a technology that allows you to write in JavaScript and HTML, and execute the code within Google's Cloud. It revolves around the Google Account.

In this presentation, we go through a demo app called Good Morning World. This app goes through the current day's Calendar events, puts a summary of those events to a Google Document, shortens the URL to the Document, and emails it to you. It also covers how to schedule it to run every morning.

For more details, go to:



Total Views
Views on SlideShare
Embed Views



0 Embeds 0

No embeds



Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.


11 of 1 previous next

  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
  • And is possible an container-bound scrip for current date in a document of google-docs with format dd/MM/yyyy?
    Are you sure you want to
    Your message goes here
Post Comment
Edit your comment

    Intro to Google Apps Script Intro to Google Apps Script Presentation Transcript

    • Google Apps Script Introduction 01-17-2013 ModMonstR.com
    • What is Google Apps Script?● A Google Cloud-based scripting technology used in the Google Apps/Drive ecosystem● Write code in JavaScript and HTML● Has native APIs to most Google services, except Google+, Blogger, and YouTube● Has Web Service support● Has App Engine integration support
    • Script Execution● Invocation Methods: ○ Google Drive ○ Google Spreadsheet ○ Web (Sites or Web App)● Scheduling Capabilities ○ By Specific Times ○ By Time Interval● Quotas ○ Goes against the executors Google Account
    • Container-Bound vs Standalone● Container-Bound scripts ○ Resides within a Google Spreadsheet ○ Goes away with the spreadsheet● Standalone scripts ○ Resides in Google Drive ○ Can be scheduled to execute ○ As a Web App, it can be deployed to the Chrome App Store
    • Google API SupportDefault and Experimental Google APIs
    • Default Google APIs● Blob ● Finance ● Script● Browser ● Gmail ● ScriptDb● Buttons ● Groups ● Sites● Cache ● Html ● Soap● Calendar ● Jdbc ● Spreadsheet● Charts ● Language ● Ui● Contacts ● Lock ● UrlFetch● Content ● Logger ● Utilities● DocList ● Mail ● Xml● Document ● Maps● Domain ● Properties
    • Experimental Google APIsThese APIs need to be enabled by going to theResources>Use Google APIs menu● AdSense● Analytics● BigQuery● Prediction● Tasks● UrlShortener
    • SampleGood Morning World
    • About Good Morning World1. Gathers Calendar events for the current day2. Write them in a Google Document3. Shorten the URL of the Document via goo.gl4. Email the shortened URL5. Schedule the script
    • Create the Script1. Go to Google Drive2. Click Create>More>Script3. Click Blank Project4. Rename Untitled project to your projects name 12 3 2 2 4
    • Initializefunction myFunction() { //Get current Date and format as a string var today = new Date(); var todayString = today.getFullYear().toString() + lPad(1+today.getMonth())+lPad(today.getDate());}function lPad(i){ return i<10?"0"+i:i;}● The current date is obtained and saved as a string in yyyymmdd format for file naming● The lPad function pads a zero to the left if the input is a single-digit number
    • Step 1. Gather Todays Calendar Events var cal = CalendarApp. getDefaultCalendar(). getEventsForDay(today); ● CalendarApp is used to reference the end- users Calendar ● getDefaultCalendar() obtains the end- users default calendar ● getEventsForDay(Date) obtains all events for the specified date ● today is the current date from previous slide
    • Step 2. Write them in a Document//Create a Google Document,//filename starts with the current datevar doc = DocumentApp.create(todayString+-Good Morning);● Create the Google Document● The filename begins with the current date in yyyymmdd format● Doing so enables the Document filenames to sort naturally
    • Step 2. Write them in a Document//Header part of the documentdoc.appendParagraph("Good Morning World");doc.appendParagraph("Below are the activities for today, "+ today);doc.appendHorizontalRule()● The header is composed of three parts: ○ A greeting ○ Language to indicate todays events ○ A horizontal rule to delineate the Calendar Events from the header
    • Step 2. Write them in a Document//Iterate through the Calendar and write to the Documentvar i = 0;for(i = 0;i<cal.length;i++){ doc.appendParagraph(basicTime(cal[i].getStartTime()) + to + basicTime(cal[i].getEndTime()) + - + cal[i].getTitle() + in + cal[i].getLocation());}● The Calendar events are stored as an array of CalendarEvent objects● Iterate via a for loop● Inside, add a paragraph to the Document with the time range, title, and location of the event
    • Step 2. Write them in a Documentfunction basicTime(t){ var output = lPad(t.getHours()) + ":" +lPad(t.getMinutes()); return output;}● basicTime formats the input time in hh:mm format● This function is called in the previous slide to format the Start and End time of the calendar event
    • Step 2. Write them in a Document//Save and close the Documentdoc.saveAndClose();● We are done with the Google Document● Save changes and Close it
    • Step 3. Shorten Document URL// Get the URL of the documentvar url = doc.getUrl();// Shorten the URLvar toShorten = UrlShortener.newUrl().setLongUrl(url)var shortUrl = UrlShortener.Url.insert(toShorten);● getUrl() gets the Documents URL● toShorten gets a url object by converting from getUrls output (string)● shortUrl contains the shortened Url
    • Step 4. Email the shortened URL// Get the email address of the active user - thats youvar emailAddress = Session.getActiveUser().getEmail();// Send yourself an email with a link to the documentGmailApp.sendEmail(emailAddress, Todays Calendar Events, Attached is a link to Document containing + todays activities + shortUrl.getId());● emailAddress contains the end-users email address● sendEmail sends the email● the results in a character
    • Step 4. Email the shortened URL● We need to enable the URL Shortener API● Click Resources● Click User Google APIs...
    • Step 4. Email the shortened URL1. Set URL Shortener API to on2. Click OK 1 2
    • Step 5. Schedule1. Go to Resources2. Click Current scripts triggers... 1 2
    • Step 5. Schedule1. Click No triggers set up. Click here to add one now. 1
    • Step 5. Schedule● Run - Pick the main function in the script● Events - Configure the scheduling● Click Save
    • Step 5. Schedule● Authorization is similar to Android apps● Each Google service accessed by the script is listed in the authorization request
    • Step 5. Schedule● Click Grant access
    • Step 5. Schedule● Confirmation of authorization
    • To Run1. Select the goodMorningWorld function2. Click on the play button to run 2 1
    • Output● Email sent containing the shortened URL
    • Output● Google Document generated by the script
    • Resources● This Presentation: ○ http://goo.gl/2dGhW● Sample Source Code: ○ http://www.modmonstr.com/search/label/Apps%20Script● Google ○ http://script.google.com ○ https://developers.google.com/apps-script/articles ○ https://developers.google.com/apps-script/videos● Stack Overflow ○ http://stackoverflow.com/questions/tagged/google-apps- script
    • Next Time● Container-bound Apps Script● Web App● Chrome Web Store deployment