Apps Script developers that wished to share their work with a larger audience have traditionally turned to the Script Gallery, which allows other users to copy and install the script into their own spreadsheets. While appropriate for custom functions and spreadsheet extensions, it didn't fit well when distributing more complex functionality and apps.

Apps Script developers that wished to share their work with a larger audience have traditionally turned to the Script Gallery, which allows other users to copy and install the script into their own spreadsheets. While appropriate for custom functions and spreadsheet extensions, it didn't fit well when distributing more complex functionality and apps.

In this blog post we'll be highlighting a newer way to distribute your scripts: deploying them as a web app and publishing them to the Chrome Web Store. Compared to the Script Gallery, the Chrome Web Store has some distinct advantages for developers:

  • Automatic updates - Change your code, do some testing, and publish a new version to update the app for all users instantly.
  • More information - Detailed descriptions, promotional images, ratings, and reviews lead to compelling listings.
  • Greater discoverability - Visit the Chrome Web Store site to learn about the benefits.

Looking through the Script Gallery we believe there are many scripts that would be a great fit for the Chrome Web Store and would benefit from the advantages listed above. Some aspects of a good candidate script are:

  • Custom UI - Users interact with your script through a custom user interface, not via custom spreadsheet functions or onEdit triggers.
  • Background processing - Your script uses time-based triggers to do work in the background and doesn't require that the Google Spreadsheet is open.
  • Not primarily about Google Spreadsheets - Your script's main focus isn't spreadsheets and you utilize a variety of services to provide separate functionality.

A great example of such a script is Gmail Meter, which was first launched in the Script Gallery but has since been published to Chrome Web Store. Now users can install and run the script without needing to create a spreadsheet, see script code, or set up triggers. It may take a little work to update a spreadsheet-based script to use the web app model, and some common tasks are:

  • Implement doGet() - Instead of showing your custom UI on the spreadsheet with Spreadsheet.show(), put the same code into the doGet() method and return the final UiInstance or HtmlOutput object.
  • Deploy as a web app - Configure your script to run as a web app, which will assign it a unique URL. In most cases you'll want the web app to run as the user so that it can access their services.
  • Remove references to active spreadsheet - When published as a web app there is no active spreadsheet, so if your script needs access to a spreadsheet then you'll need to use SpreadsheetApp.openById() instead. You can use the DocsList service or the DocsListDialog UI widget to help users locate the desired spreadsheet.
  • Handle multiple users - When published as a web app users access the same copy of the script, so you may need to change the way you organize data to avoid conflicts. UserProperties work well for small settings, and when using ScriptDb make the user's login ID or email address part of the objects so that you can filter for them later.

Publishing to the Chrome Web Store only takes a few clicks, and we provide instructions for the process in our documentation. We hope that you are inspired to take your scripts to the next level, and if you have any questions along the way feel free to reach out to us on StackOverflow or Google+.


Eric Koleda profile

Eric is a Developer Programs Engineer based in NYC on the Google Apps Script team. He's previously worked with the AdWords API and enterprise content management software.

At Google I/O in June, we launched two new features that made it easier to build and distribute web apps with Google Apps Script. First, we added the ability to deploy web apps that run as the user. Second, we added simple integration for publishing web apps that you’ve built with Apps Script to the Chrome Web Store.

At Google I/O in June, we launched two new features that made it easier to build and distribute web apps with Google Apps Script. First, we added the ability to deploy web apps that run as the user. Second, we added simple integration for publishing web apps that you’ve built with Apps Script to the Chrome Web Store.

Recently we’ve come across some new and useful web apps that developers have built using Apps Script and published in the Chrome Web Store. In this blog post, we’d like to highlight a few of those.

Print Phone Book is a helpful utility that will generate a phone book document from selected Contacts groups. The phone book document is stored conveniently in your Google Drive, where you can access it, share it, or print it. The app will also email you a link to the document to make it even easier to find.

Envelopes for Google Docs is a web app that will create a document in your Google Drive with the page size and margins you specify, making it easier to print envelopes from a Google Document.

Gmail Print All for Chrome helps you quickly export messages into a document in your Google Drive that you can print, save as a PDF, share with others, or store in a way that works for you. All you do is add messages to a Gmail label and then select that label and click a button in the web app. Each message thread gets a page of its own with the subject at the top, the number of messages in the thread and messages organized by the date.

Archiver for Gmail is a web app that will analyze your inbox and move all the big attachments (by default > 3MB - but you can change this threshold) to your Google Drive. The script will also save an HTML copy of the whole thread, so that you can delete every email containing big attachments if you want to. Finally, all the messages containing relevant attachments will be labelled, so that you can organize your inbox even better.

Feed+ is a sample app that allows you to create an RSS feed of public Google+ activities and quickly add it to your Google Reader account. It was created using Google Apps Script, and demonstrates the usage of the HtmlService, ContentService, ScriptDb, and the Google+ API.

To try these and other web apps built using Apps Script, just visit the Chrome Web Store. If you’re interested in building and deploying your own web apps with Apps Script, see our documentation for web apps and publishing to the Chrome Web Store.


Jan Kleinert profile | twitter

Jan is a Developer Programs Engineer based in NYC, focusing on helping developers get the most out of Google Apps Script. Prior to Apps Script, she worked on Commerce, helping merchants integrate with Google Checkout and on Chrome, helping developers build great web apps.

Hello Los Angeles! Following on the heels of our hackathon in Austin, Texas, we’ve decided that it’s time to bring the party to the City of Angels in sunny southern California. We’ll be hosting an Apps Script hackathon in our recently opened Los Angeles office on Tuesday, November 13th, 2012 between the hours of 2-8pm Pacific Time. We invite anyone that either uses or wants to learn about Google Apps Script to come and meet the team!

Hello Los Angeles! Following on the heels of our hackathon in Austin, Texas, we’ve decided that it’s time to bring the party to the City of Angels in sunny southern California. We’ll be hosting an Apps Script hackathon in our recently opened Los Angeles office on Tuesday, November 13th, 2012 between the hours of 2-8pm Pacific Time. We invite anyone that either uses or wants to learn about Google Apps Script to come and meet the team!

We’ll start off with a quick introduction to Apps Script followed by a short tutorial. At that point, we’ll break off into groups or individual work to either build apps or work through tutorials - both are fine, and you’ll have direct access to the Apps Script team to help you with any questions or ideas. We’ll provide food, drinks, power and wifi - you just bring your laptop, your creativity, and your appetite for code! Check out the detailed Google Sites page, RSVP once you know you can make it, and tell your friends about the event!

Official event page: https://sites.google.com/site/appsscripthackathonlosangeles

Hope to see you there!

- Ikai

Ikai Lan   profile

Ikai is a Developer Programs Engineer working on Google Apps Script. Prior to Apps Script, he worked on Google App Engine. Ikai is an avid technologist, consuming volumes of material about new programming languages, frameworks or services, though more often than not you'll find him advocating pragmatism over dogma in the solutions he proposes. In his free time he enjoys the great outdoors, winning Chinese language karaoke contests and playing flag football. He resides in New York City, where he watches in anguish as his favorite sports teams from the San Francisco Bay Area implode season after season.

Did you know you can write a complete Google Drive App with JavaScript that runs completely in the web browser? You can! Your browser-based application, including Chrome extensions, can take advantage of our client library, or just use CORS requests to the API.

Did you know you can write a complete Google Drive App with JavaScript that runs completely in the web browser? You can! Your browser-based application, including Chrome extensions, can take advantage of our client library, or just use CORS requests to the API.

Your app can support all the functionality of the Drive API, including uploading files, downloading files, tracking changes, listing files and managing revisions. Also you can take advantage of our user interface components that make opening and sharing files easy.

We are really keen to offer first-class support to browser-based applications, so we have added JavaScript snippets to all our API reference documentation. Please let us know how we are doing by posting to Stack Overflow.

Want to try it out? Check out our Javascript Quickstart Guide, which helps you get your application up and running in five minutes or so.

Ali Afshar profile | twitter

Tech Lead, Google Drive Developer Relations. As an eternal open source advocate, he contributes to a number of open source applications, and is the author of the PIDA Python IDE. Once an intensive care physician, he has a special interest in all aspects of technology for healthcare

With the arrival of the new Google Drive API v2, we are deprecating the Google Documents List API v3. We are confident that the Google Drive API covers all the functionality of the Documents List API, in addition to adding many improvements, including Drive UI Integration, a finer grained security model, and a better client library experience.

With the arrival of the new Google Drive API v2, we are deprecating the Google Documents List API v3. We are confident that the Google Drive API covers all the functionality of the Documents List API, in addition to adding many improvements, including Drive UI Integration, a finer grained security model, and a better client library experience.

What does this mean for your app?

The Documents List API v3 will remain in action for more than a year, as per our deprecation policy, so there’s no rush, but we encourage you to migrate your code to the new platform. Documentation is available with samples in multiple languages and a migration guide outlining some of the major transition points.

If you have any questions or issues, please ask them on StackOverflow.com, where our team is waiting to hear from you.

Ali Afshar profile | twitter

Tech Lead, Google Drive Developer Relations. As an eternal open source advocate, he contributes to a number of open source applications, and is the author of the PIDA Python IDE. Once an intensive care physician, he has a special interest in all aspects of technology for healthcare

Not long after the Drive SDK was first released, we started receiving requests for a simpler developer and user experience. It took too long for developers to get started, and users were sometimes confused by the ways apps were installed. We’re now announcing a new feature that helps address these concerns: the Drive installation scope.

Not long after the Drive SDK was first released, we started receiving requests for a simpler developer and user experience. It took too long for developers to get started, and users were sometimes confused by the ways apps were installed. We’re now announcing a new feature that helps address these concerns: the Drive installation scope.

As the name suggests, this new OAuth 2.0 scope lets users install an app by approving an access request. Along with all the other levels of access you can request from users, it’s now possible to ask users for permission to install your app in their Drive.

This means that an app, or an app’s promotion page, could present an option to “Install this app in Google Drive,” and then users who select this option would interact with an OAuth 2.0 dialog that requests the installation scope. For example, the following script creates an “Add to Google Drive” button that could be embedded in a web page:

<script src="https://apis.google.com/js/client.js"></script>
<script>
var CLIENT_ID = '123456789.apps.googleusercontent.com'
function installDriveApp() {
  gapi.auth.authorize({
    client_id: CLIENT_ID,
    scope: 'https://www.googleapis.com/auth/drive.install',
    immediate: false
  }, function(authResult) { // Callback when installation complete });
}
</script>
<button onclick="installDriveApp();">Add to Google Drive</button>

On clicking this button, the user sees a standard OAuth 2.0 dialog box like the following (text for the installation scope is expanded in this example):

When the user approves these scopes, the app is installed for the user. Then, once it is installed this way, the app appears in the user’s Open with options as well as the Create > more contextual menu for files of registered MIME types.

Apps still need to specify primary and secondary MIME types when they enable the Drive SDK in the APIs console. But, unlike before, there is no need to install via the Chrome Web Store in order to get UI integration -- web store integration is entirely optional (though recommended).

Essentially, Drive now offers three levels of integration, which apps can combine according to their needs:

  • Simple API access with the Drive API enabled.
  • UI integration, with API access, the Drive SDK enabled, and OAuth-based installation.
  • CWS-based integration, with all of the above plus web store installation and marketing/upsell features.

For guidance in getting started integrating your app in any of these ways, see “Build a Drive Web App” or "Integrate with the Drive UI" in the SDK documentation.

We still recommend that developers consider the many benefits of creating a Chrome Web Store listing for their application. In addition to providing ease of installation for users “shopping” in the Drive app collection, a web store listing provides helpful features to market and promote an app. Our usage analysis shows that apps in the Chrome Web Store receive more usage than apps that aren’t listed. But now, with the installation scope, you can get started developing and testing your app more quickly and then list it in the Chrome Web Store when you’re ready.

If you have any questions about the installation scope, don’t hesitate to let us know on our Stack Overflow tag, google-drive-sdk.

Eric Gilmore

Eric is a technical writer working with the Developer Relations group. Previously dedicated to Google Apps APIs, he is now busy writing about all aspects of the Google Drive SDK.

Editor’s Note: Guest author Bruce McPherson is a contributor to the Excel Liberation website and blog. -- Eric Koleda

If you are new to Google Apps Script and the JavaScript programming language, migrating legacy automation code written in Microsoft's Visual Basic for Applications (VBA) can be a daunting task. This blog post describes a Google Apps Script library which mimics the behavior and calling structure of common VBA functions, allowing you to more easily convert your existing applications.

Editor’s Note: Guest author Bruce McPherson is a contributor to the Excel Liberation website and blog. -- Eric Koleda

If you are new to Google Apps Script and the JavaScript programming language, migrating legacy automation code written in Microsoft's Visual Basic for Applications (VBA) can be a daunting task. This blog post describes a Google Apps Script library which mimics the behavior and calling structure of common VBA functions, allowing you to more easily convert your existing applications.

Retaining compatibility

If you are planning to continue to use VBA, you can minimize both the work involved in maintaining the same capability in both platforms, and in porting from one to the other, by preserving backwards compatibility with VBA. This means breaking a few JavaScript conventions, but the result is worth it.

For example, JavaScript variables are normally written in lowerCamelCase, with classes being in UpperCamelCase. VBA is not case sensitive, and uses hungarian notation by convention, except for the built-in functions, which have a capitalized first letter. Since the objective here is to minimize change, I have decided to retain this capitalization for VBA functions replacements (for example CStr(), Mid() etc. ).

In VBA, indices (normally) start at 1, while in JavaScript they start at 0. Since these functions are to minimize change in application written in VBA, they also start at 1. For example Mid(x, 1, 2) means the first 2 characters of
string x in both VBA and JavaScript versions.

Enumeration of collections

JavaScript does not have a collection object. The vEquivalents library provides an implementation of a collection class so that continuity for migrated code that relies on the collection can be maintained. But how to enumerate through that collection? There are a number of ways, but the forEach() method of the collection most closely resembles the 'For Each member in collection' approach VBA developers are familiar with. The syntax may seem a little fiddly at first, since it passes the code you want executed against each member of the collection as an anonymous function.

var coll = new collection();
// by index
for (var i=1; i <= coll.count() ;i++) {
  DebugPrint (coll.item(i));
}
// by key
for (k in coll.keys()) {
    DebugPrint (coll.item(k));
}
// forEach 
coll.forEach(
  function (item, index) {
    DebugPrint (item, index);
  }
);

Including vEquivalents in your Google Apps Script Project

With the great new libraries functionality, you can now include these scripts in your project by using the project key "MEQ3tE5y5_cTOAgUbUKSIAiz3TLx7pV4j", or you can make a copy of the scripts directly to include in your own project. You will find a selection of other scripts in the library, but the VBA equivalents are all in the module vEquivalents. Note that as you include external libraries in your project (see here for how), you need to prefix the functions with the library identifier (for example mcpher.CStr())

Examples

You can access the documentation here, and you will see that most of the common VBA functions are included. Some examples are

var x = Trim(s);
var x = Len(s);
var a = Split(s);
var x = Instr(1, s1, s2);
var d = DateSerial(y, m, d);
MsgBox(s);
var x = InputBox(s);
DebugAssert (b, s);
var w = ActiveSheet();

Going beyond the built-in VBA functions

Using the same approach, I have converted many other VBA utility classes and procedures built over time and added them to this library. This means that the implementation of something on either platform not only looks the same, but can be accomplished in hours or even minutes. For example, on my blog I publish a daily API, implemented in both VBA and Apps Script (both versions even use ScriptDB for the same parameter data). Here's a recent one.

function testUkPostcodes() {
  mcpher.generalDataSetQuery ("uk postcodes", "uk postcodes", "postcode");
}

Public Sub testUkPostcodes()
  generalDataSetQuery "uk postcodes", "uk postcodes", "postcode"
End Sub

You can find more projects that have been migrated this way here.


Bruce McPherson   profile | twitter

Bruce McPherson is a contributor to Excel Liberation website and blog, and advocate for open data.

We keep adding new features to the Drive SDK and the Drive API, but always want to make it easy for new developers to get started. That’s why we are introducing a quickstart guide in 6 languages to run your first Drive app in less than 10 minutes: Java, Python, PHP, .NET, Ruby and Go.

We keep adding new features to the Drive SDK and the Drive API, but always want to make it easy for new developers to get started. That’s why we are introducing a quickstart guide in 6 languages to run your first Drive app in less than 10 minutes: Java, Python, PHP, .NET, Ruby and Go.

At the end of this short guide, you’ll have:

  • set up your Google APIs Console project
  • installed the Google supported client library in your favorite language
  • run your first command-line app to authorize and upload a file to Google Drive

We are also covering this quickstart guide in our Google Developers Live sessions: Python, PHP and .NET are already available and check-out our schedule for the remaining languages.

Once you are up and running, add more features such as reading a file’s metadata and content, update an existing file, integrate with the Drive web UI and list your Drive app on the Chrome Web Store to drive in more users!

Questions, feedback? Let’s follow-up on StackOverflow under the google-drive-sdk tag.


Alain Vongsouvanh   profile

Alain is a Developer Programs Engineer working on the Google Drive SDK. Born and raised in Paris, he got exported to Google’s headquarters in Mountain View, CA.