3
votes

Google Apps has some simple triggers: https://developers.google.com/apps-script/guides/triggers/

One of which is onEdit. As documented, onEdit fires for Google Spreadsheets, but it does not fire for Google Docs.

Is there a clean way to detect when the user has changed the document, and run a script when that happens?

1
I don't know anything about this API, but it looks like it might be worth taking a look at: Files WatchAlan Wells
Files Watch API is the one if you are not forced to used Apps script for your work. Btw, another similar q/a - stackoverflow.com/questions/19781406/google-doc-script-oneditIdo Green
you might also be interested in reading this answerSerge insas

1 Answers

2
votes

This is not a complete answer, but this may (not sure) help you based on your actual requirement. You can have a function like this and then using installed triggers you can call this function every minute to poll document and check whether someone has edited it or not.

 function isEdited()
    {
      var MyDoc = DocumentApp.getActiveDocument().getBody();
      var Text = MyDoc.editAsText().getText();
      var DocLen= Text.length;
      if(DocLen!= PropertiesService.getDocumentProperties().getProperty('DocLen'))
      {
        CallYourFunction();
        PropertiesService.getDocumentProperties().setProperty('DocLen', DocLen)
      }    
    }

Is 60 sec delay okey in your service... 60 sec is the maximum delay that can occur here.