G Suite Developers Blog
Information for G Suite Developers
Publish your scripts to the Apps Script Gallery
March 10, 2010
Today, we are excited to make Google Apps Script available to everyone. Some of you may already be familiar with Google Apps Script within Google Apps, but in case you are new to it,
Google Apps Script
provides a powerful and flexible scripting environment that lets you automate actions across your spreadsheets, sites, calendars, and many other services.
An important new feature of Apps Script is a script gallery, where developers can easily publish their scripts to make them accessible to everyone. You can find the gallery by going to
Insert
and then selecting
Script...
in any Google spreadsheet.
Recently, the Google Apps team in New York put together a
Movie Night
script to help us easily figure out which movies were playing nearby and vote for our favorites - you can read more about it
here
. Let’s take a closer look at how the script works and how we published it to the new Apps Script Gallery.
We start by bringing up the script editor from a spreadsheet (
Tools -> Scripts -> Script editor...
).
The first step is to fetch a list of movies playing in a given area at a given time. We use the Google search results for a movie query as follows:
var
results = UrlFetchApp.fetch(
'http://www.google.com/movies?hl=en&near='
+
zipcode +
'&dq=movies&sort=1'
).getContentText();
var
doc = Xml.parse(results,
true
);
We can then use Apps Script’s handy
Xml service
to parse the results. The next step is to send an email to our friends asking them to vote. This is the slightly tricky part:
In the spreadsheet, select
Form -> Create a form
to open the form creation window.
Add two questions, one titled “Movie”, and the other “Attendee” - we don’t care too much about any other text as it will all be replaced by the script at run-time.
Close the form creation window.
In the spreadsheet, select
Form -> Go to live form,
and copy the ‘formkey’ parameter from the address bar.
Open the script in the editor, and insert the ‘formkey’ into line 2 of the script.
Phew! That was the tricky part. In summary, we just created a form for the spreadsheet, but instead of using that form directly, we’re going to use a form that is dynamically generated by the script. However, we still need the special key to correctly route submissions to the spreadsheet (and to validate those submissions).
After that, we can put together a list of recipients by calling the
contacts service
and reading the Gmail ‘Friends’ group:
var
contactGroup = ContactsApp.findContactGroup(
’System Group: Friends’
);
var
people = contactGroup.getContacts();
Lastly, we put the movie thumbnails and descriptions in the email body - tailored to each recipient, so that we’ll know who voted:
var
emailBody = "";
for
(
var
i
in
movies) {
// add the image, title etc to emailBody (as HTML)
}
var
addresses = getFriends_();
for
(
var
i
in
addresses) {
var email = email_header + form_key + emailBody + email_footer;
MailApp.sendEmail(addresses[i],
"Movie tonight?"
, "", {htmlBody: email});
}
Check out the
documentation
and get started building your scripts - we look forward to seeing your gallery submissions. To share your masterpiece with the world, select
Share -> Publish Script...
from the script editor - it's that easy!
Also, for those attending Google I/O this year, be sure check out the
Google Apps Script talk
on the Enterprise track.
Posted by
Nikhil Singhal, Google Apps Script Engineer
Free Trial
Labels
.NET
3
#io15
1
#io16
1
Admin SDK
10
Administrative APIs
31
AdSense
1
analytics
5
Android
8
API
3
APIs
3
App Engine
5
Apps
1
Apps Script
118
Audit
2
Auth
5
billing
4
Charts
2
Chrome OS
1
classroom
3
Cloud Storage API
1
Community
1
decks
1
Design
1
Developers
12
Directory API
3
Drive
4
Drive SDK
41
execution API
2
Firebase
1
Forms
1
Freemium
1
Fusion Tables
2
G Suite
24
Gadgets
5
Gmail
7
Gmail APIs
23
Google
3
Google APIs
36
Google Apps
33
Google Apps Marketplace
7
Google Calendar API
25
Google Classroom
4
Google Cloud Directory
1
Google Contacts API
4
Google Data Protocol
8
google docs
5
Google Docs API
22
Google Drive
8
Google Drive SDK
7
Google Forms
8
Google I/O
3
Google Prediction API
3
Google Profiles API
2
Google sheets
11
Google Sheets API
7
Google Sites API
5
Google Slides API
10
Google Spreadsheets API
5
Google Talk
1
Google Tasks API
8
Google+
3
googlenew
1
Groups
2
GSuite
3
Guest Post
43
Hangouts Chat API
1
I
1
Inbox
1
iOS
2
issue tracker
1
ISVs
2
java
1
JavaScript
6
marketing
3
Marketplace
47
Marketplace ISV Guest
21
Migration
2
Mobile
5
mpstaffpick
1
oauth
16
OpenID
8
PHP
1
presentations
1
python
7
realtime API
2
Resellers
2
Ruby
1
SaaS
1
security
5
Sheets API
3
spreadsheets
3
Staff Picks
2
tool
1
tools
2
tutorials
2
video
4
videos
1
webinar
2
Archive
2018
Jul
Jun
May
Mar
Feb
Jan
2017
Dec
Nov
Oct
Sep
Aug
Jul
Jun
May
Apr
Mar
Feb
Jan
2016
Dec
Nov
Oct
Sep
Aug
Jul
Jun
May
Apr
Mar
Jan
2015
Dec
Oct
Sep
Aug
Jul
Jun
May
Apr
Mar
Feb
2014
Dec
Oct
Sep
Aug
Jul
Jun
May
Mar
Feb
Jan
2013
Dec
Nov
Oct
Sep
Aug
Jul
Jun
May
Apr
Mar
Feb
Jan
2012
Dec
Nov
Oct
Sep
Aug
Jul
Jun
May
Apr
Mar
Feb
Jan
2011
Dec
Nov
Oct
Sep
Aug
Jul
Jun
May
Apr
Mar
Feb
Jan
2010
Dec
Nov
Oct
Sep
Aug
Jul
Jun
May
Apr
Mar
Feb
Feed
Google
on
Follow @gsuitedevs