title: How to create a trigger programmatically for an open event in Google Apps Script
body: <p>I'm playing around with Google Apps script and encountering a weird error when trying to programmatically create a trigger (not bound to a specific file or anything).</p>
  
  <p>I am trying to run a certain code - basically to edit a document in Google Docs whenever it opens, but I'm experiencing this error: </p>
  
  <blockquote>
    <p>Unexpected error while getting the method or property create on object
    ScriptApp.DocumentTriggerBuilder. (line 9, file "Code")DetailsDismiss</p>
  </blockquote>
  
  <p>Here's the code that I'm using: </p>
  
  <pre><code> /**
   * Creates a trigger for when a spreadsheet opens.
   */
  function createSpreadsheetOpenTrigger() {
    var d = DocumentApp.getActiveDocument();
    ScriptApp.newTrigger('myFunction')
          .forDocument(d)
          .onOpen()
          .create();
  }
  
  
  function myFunction() {
       // change the body or something...
  }
  </code></pre>