title: Scripts on Google Sheets document only run for me (owner)
body: <p>I have a shared Google Sheet from my Drive with two buttons tied to functions  created in Tools->Script Editor.  The basic problem is that everything appears to run fine for me, but not for anyone else with the link.  I've also tried logging off and clicking the link, and it did not run for me (vague message about script encountering error after many seconds).  I've made sure to enable full edit for anyone with the link, but again same issue.</p>
  
  <p>In case it's something script-related, I'll post below just in case.  It basically selects 10 rows at random from a 2-column set of rows (e.g. located at A1 through B100), and pastes what it selected in H1:I10. If done again, it would choose 10 new things from remaining data and post to H11:I20, etc.  I make use of "global" variables in the project properties to remember state.</p>
  
  <pre class="lang-js prettyprint-override"><code>var ss = SpreadsheetApp.getActiveSpreadsheet();
  var sheet = SpreadsheetApp.getActiveSheet();
  
  // Restart the selection process from the full set of data
  //  This is effectively a hack for global variables/persistence
  function resetData()
  {
    var dataRange = sheet.getRange("dataRange");
    var data = dataRange.getValues();  
  
    // Save original data
    PropertiesService.getScriptProperties().setProperty('data', JSON.stringify(data));  
  
    //Browser.msgBox("data successfully set to:\n"+data +"\n\nThere are "+data.length+" items.");    
    var itemsRemainCell = sheet.getRange("itemsRemainCell");
    itemsRemainCell.setValue(data.length + " items remain.");
  
    // Set area for output data (changes due to items remaining)
    PropertiesService.getScriptProperties().setProperty('outputStart', "H1");
    PropertiesService.getScriptProperties().setProperty('outputEnd', "I10");
  
    // Clear possible previous data and borders
    sheet.getRange("H1:I100").clear();
  }
  
  // Select n things from what remains of data, and possibly copy them to some location
  function select10() {
    data = JSON.parse(PropertiesService.getScriptProperties().getProperty('data'));
  
    if (data.length &lt; 10)
    {
      Browser.msgBox("There are only "+data.length+" items left to pick");
      return;
    }
  
    var selection = new Array();
    for(var i=0; i&lt;=9; ++i)
    {
      var index = getRandomInt(0, data.length-1);
      var item = data[index];
      selection[i] = item;
  
      data.splice(index, 1);
    }
    //Browser.msgBox(selection.toString());
  
    var outputStart = PropertiesService.getScriptProperties().getProperty('outputStart');
    var outputEnd = PropertiesService.getScriptProperties().getProperty('outputEnd');
  
    // Update with decremented length
    var itemsRemainCell = sheet.getRange("itemsRemainCell");
    itemsRemainCell.setValue(data.length + " items remain.");
  
    // Write out selection in some parallel columns
    var writableRange = sheet.getRange(outputStart+":"+outputEnd);
    writableRange.setValues(selection);
    writableRange.setBorder(true, null, null, null, false, false, "red", SpreadsheetApp.BorderStyle.DASHED);
  
    // Increment writable start/end 
    outputStart = "H" + (parseInt(outputStart.substring(1))+10); 
    outputEnd = "I" + (parseInt(outputEnd.substring(1))+10);
  
    // Save updated/spliced data
    PropertiesService.getScriptProperties().setProperty('data', JSON.stringify(data));
    PropertiesService.getScriptProperties().setProperty('outputStart', outputStart);
    PropertiesService.getScriptProperties().setProperty('outputEnd', outputEnd);
  }
  
  // Returns a random integer from min to max, inclusive
  function getRandomInt(min, max) {
    return Math.floor(Math.random() * (max - min + 1)) + min;
  }
  </code></pre>
  
  <p>Sheet link (I made a copy, but don't go too crazy editing it)
  <a href="https://docs.google.com/spreadsheets/d/1UnufKPE0-sO3TXBGRWMbErE_FINhx3Gx8VQNKtIMsH4/edit?usp=sharing" rel="nofollow noreferrer">https://docs.google.com/spreadsheets/d/1UnufKPE0-sO3TXBGRWMbErE_FINhx3Gx8VQNKtIMsH4/edit?usp=sharing</a></p>
  
  <p>I've also seen <a href="https://productforums.google.com/forum/#!msg/docs/hiKxM9ahnc4/doQCYee6y10J" rel="nofollow noreferrer" title="this post">this post</a> about "by design" but I thought it should not affect me if I give anyone with the link edit privs...</p>
  
  <p>[Edit] I just realized that completely anonymous users cannot run the scripts, for whatever reason.  One must be logged in, and then as in arturro's case, a popup will come up asking you to authorize running of the script.  Anonymously, (e.g. logging out and then clicking doc link) there is no confirmation popup, so  for some reason the script runs and times out.</p>