Code Monkey home page Code Monkey logo

appsscriptloader's Introduction

Load Scripts from Google Drive

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 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, 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 shows up in the url: https://docs.google.com/file/d/{DOCUMENT ID}/edit .

  4. Create a new Google Apps 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.

function doGet() {
  loadFile('DOCUMENT ID');
  //your app entry here
}

function bootstrap() {
  //reference permissions you might need
  Browser.msgBox('');
}

function loadFile(fileId) {
  var fileContent = DocsList.getFileById(fileId).getContentAsString();
  try {
    eval(fileContent);
  } catch (e) {
    var fileName = DocsList.getFileById(fileId).getName();
    e.message = [
      "fileName", "line " + e.lineNumber, e.message
    ].join(" | ");
    throw e;
  }
}

That's it! 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.

appsscriptloader's People

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.