danthareja / node-google-apps-script

[DEPRECATED - use clasp instead] The easiest way to develop Google Apps Script projects
MIT License
353 stars 70 forks source link

Rejecting file ID on `gapps init` when ID begins with M #38

Closed rafaelalemar closed 8 years ago

rafaelalemar commented 8 years ago

You guys have committed a version that block gapps innit when ID begins with M, but all my bounded scripts starts with M. I know I can't push code to bounded scripts, but I could pull it. I used to backup my bounded scripts this way. Any work around?

hess-g commented 8 years ago

Rafael - The "m" ID is the project key. You need to use the Drive File ID for the script, which begins with a "1", and can be obtained from the URL when you open the script editor from your bound script.

On Tue, Jul 5, 2016 at 1:48 PM, Rafael Vidal notifications@github.com wrote:

You guys have committed a version that block gapps innit when ID begins with M, but all my bounded scripts starts with M. I know I can't push code to bounded scripts, but I could pull it. I used to backup my bounded scripts this way. Any work around?

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/danthareja/node-google-apps-script/issues/38, or mute the thread https://github.com/notifications/unsubscribe/AMPN9Glmd0VccPkN86hVBn7G086M4tFdks5qSpjkgaJpZM4JFXLA .

oshliaer commented 8 years ago

The eval could help for this.

Code.gs

function onOpen(){
  magic(getSource(), 'onOpen');
}

function getSpreadsheetId(){
  magic(getSource(), 'getSpreadsheetId');
}

function magic(source, fn){
  eval('(' + source + ')')(fn);
}

function getSource(){
  return HtmlService.createHtmlOutputFromFile('source').getContent();
}

function doGet(){
  return ContentService.createTextOutput(getSource());
}

source.html

function(fn){

  var ___ = {};  
  ___.args = Array.prototype.slice.call(arguments, 1);

  ___.onOpen = function(){
    SpreadsheetApp.getUi().createMenu('menu').addItem('get id', 'getSpreadsheetId').addToUi();
  };

  ___.getSpreadsheetId = function(){
    SpreadsheetApp.getUi().alert(SpreadsheetApp.getActive().getId());
  };

  return ___[fn].apply(undefined, ___.args);
}
rafaelalemar commented 8 years ago

@hess-g Thanks for the quick reply. My old bound script file ID all start with M. I just created a new spreadsheet and open the script editor to confirm the file ID starts with 1. But my old ones still start with M and the project key starts with 1. So, I pick up the project key and it worked...

@oshliaer Your script would give me the spreadsheet id, not the script ID.