title: Creating a Google Apps Script which Automatically Executes on Upload
body: <p>I have an interesting fairly simple problem I am trying to solve but I am at a loss on the proper code to get this to working correctly.</p>
  
  <p>Basically, I have an very old local application running which allow me to print a receipt of a transaction. I have the ability to enable this receipt to be printed to a specific file within a specific directory on my computer or I can set it up to print out automatically to a printer on my computer. Currently I print the data out to a file, then copy the contents of that file and paste it into a word document template and then manually go through and format the data so it looks clean (I should note that the data prints out in fixed field format requiring a specific font and size so its pasts correctly. After all this is done I then email the word or pdf document out.</p>
  
  <p>Essentially what I am trying to do here is automate this method and I thought this should be possible using a Google Apps Script.</p>
  
  <p>My thought here was that it should be possible to:</p>
  
  <ol>
  <li>save all the original files from my application to a specific
  directory on my computer</li>
  <li>sync that folder with google drive</li>
  <li>have a google apps script automatically execute upon upload</li>
  <li>have the google apps script automatically use a specific document
  template I create with a header/footer and then paste all the
  contents from the new file which was uploaded</li>
  <li>have the google apps script pattern match certain elements within the contents of
  the document and properly format it.</li>
  <li>save the document to a specific location with a specific file naming convention</li>
  <li>automatically email the document as a doc or pdf based upon a
  specific regex matched field within the source document.</li>
  </ol>
  
  <p>Could anyone provide a specific code example which demonstrates how Google apps scripts can be utilized to monitor the contents of a specific Google drive folder to trigger an event immediately after a new file is uploaded?</p>
  
  <p>Thanks in advance!</p>