title: How to apply Google Apps Script to filtered emails?
body: <p>I currently have a script in place to auto reply to messages sent over the weekend, checking for unread messages in the last 5 minutes, and then replying and marking as read.</p>
  
  <p>I was wondering if it were possible to only have this script look for unread messages INSIDE a specific folder/filter. The reason for this is we have lots of different emails going to this box, and we don't want auto replies to most emails, just some, which have been filtered.</p>
  
  <p>If it is not possible to have a script look inside a filter, is it possible to only have to reply to messages that match a certain condition?</p>
  
  <p>This is the current script I have in place, running every five minutes:</p>
  
  <pre><code>function autoReply() {
  var interval = 5;    //  if the script runs every 5 minutes; change otherwise
    var date = new Date();
    var day = date.getDay();
    var hour = date.getHours();
    if ([6,0].indexOf(day) &gt; -1 || (day == 1 &amp;&amp; hour &lt; 10) || (day == 5 &amp;&amp; hour &gt;= 15)) {
      var timeFrom = Math.floor(date.valueOf()/1000) - 60 * interval;
      var threads = GmailApp.search('is:inbox after:' + timeFrom);
      for (var i = 0; i &lt; threads.length; i++) {
        if (threads[i].isUnread()){
        threads[i].reply("Thank you for reaching CTGINC. Your email is very important to us, one of our customer service experts will respond within the next 24-48 hours. Thank you!");
        threads[i].markRead();
        threads[i].markImportant();
        }
      }
    }
  }
  </code></pre>