Friday, August 17, 2012

Use Any Editor with Google Apps Script

The excellent syncing built into Google Drive makes it easy to create javascript files on your computer and run them within Google Apps. This approach means you can use your favorite text editor rather then the online code editor, but still easily test in Google Apps Script without needing to copy and paste repeatedly.

You can even write code in coffeescript and have it automatically compile to javascript and sync to the cloud, ready to test. Finally, although Google recently introduced Libraries in Google Apps Script, this approach represents a simple way to share code between projects while still supporting granular permissions.

To get started:
  1. Set up Google Drive syncing on your development computer.
  2. Create a new javascript or coffeescript file in your Google Drive folder (coffeescript folks may want to set up an automatic compilation watcher on that folder).
  3. Open your file in the online Google Drive. It will show in a document viewer, but the important thing to find is the document's id. This is in the url: https://docs.google.com/file/d/{DOCUMENT ID}/edit .
  4. Create a new Google Apps Script application and paste in the loader code below. Be sure to customize it for the document id you found in step 3. Also, if your code requires any permissions, you'll have to reference them here since Apps Script isn't able to find them in a loaded file.

That's it! When you save the file on your computer, it will sync to Google and Apps Script will load the latest version.  If you distribute your application to other users (for example, by including it within a shared spreadsheet) remember to set the sharing permissions on the javascript files you are loading or a folder containing both the application and javascript files.

You may also be interested in my open source Apps Script user interface library.

Tuesday, August 14, 2012

UiBot - Google Apps Script User Interface Library

I've been playing around with Google Apps Script lately, and I thought I'd share a small class I wrote to make building user interfaces with the UI Service a little more pleasant. With this library, you can specify an interface through a simple declarative JSON syntax, rather then a lot of chained function calls (or the GUI builder). It also includes some helpers to reduce the amount of code needed to build forms.

While you can also create a UI with Google's recently released Html Service, the UI Service has the nice properties of sharing a common design with Google Docs and working smoothly across all of the browsers Docs supports. UiBot works with all of the ui elements supported by the UI Service.

Details and a brief tutorial are at:
https://github.com/gotdan/UiBot#overview

Here's a snippet of UiBot code: