title: Google Apps Script targeting header on doc with different first page headers
body: <p>I have a simple little apps script that refreshes our dynamic logo on request. The problem is I can't target the header if the designer checks "Different first page header/footer" checkbox. Is there away to target the different header if it's checked?</p>
  
  <p>Here is the code I'm currently using:</p>
  
  <pre><code>function onOpen() {
    DocumentApp.getUi().createMenu('Branding')
      .addItem('Update Branding', 'updateLogo')
      .addToUi();
  }
  
  function updateLogo() {
    var doc = DocumentApp.getActiveDocument();
    var header = doc.getHeader();
    if (header) {
      var images = header.getImages();
      var logoWidth = 250;
      if (images.length &gt; 0) {
        var image = images[0];
        logoWidth = image.getWidth(); // pixels
        image.removeFromParent();
      }
  
      var freshLogo = UrlFetchApp.fetch("http://example.com/logo.jpg").getBlob();
      var newImage = header.insertImage(0, freshLogo);
  
      var logoRatio = newImage.getHeight() / newImage.getWidth();
  
      newImage.setWidth(logoWidth);
      newImage.setHeight(newImage.getWidth() * logoRatio);
    }
  }
  </code></pre>