title: Formatting text with apps script (Google Docs)
body: <p>I have made some apps script to format text in a Google Doc, but:</p>
  
  <ol>
  <li>I can't figure out how to stop the script breaking when the text isn't found.</li>
  <li><p>The script doesn't look very efficient.</p>
  
  <pre><code>// Set the whole body to Roboto 10
  var FontStyle = {};
  FontStyle[DocumentApp.Attribute.FONT_FAMILY] = 'Roboto';
  FontStyle[DocumentApp.Attribute.FONT_SIZE] = 10;
  
  body.setAttributes(FontStyle);
  
  // Set some elements to bold
  var BoldStyle = {};
  BoldStyle[DocumentApp.Attribute.BOLD] = true;
  
  var pattern1 = "Private &amp; Confidential";
  var found1 = body.findText(pattern1);
  found1.getElement().setAttributes(BoldStyle)
  
  var pattern2 = "Your Reference:";
  var found2 = body.findText(pattern2);
  found2.getElement().setAttributes(BoldStyle)
  
  var pattern3 = "Our Reference:";
  var found3 = body.findText(pattern3);
  found3.getElement().setAttributes(BoldStyle)
  
  // Set some elements to right align
  var RightStyle = {};
  RightStyle[DocumentApp.Attribute.HORIZONTAL_ALIGNMENT ] = 
  DocumentApp.HorizontalAlignment.RIGHT;
  
  var pattern4 = "\\[Date\\]";
  var found4 = body.findText(pattern4);
  found4.getElement().getParent().setAttributes(RightStyle);
  </code></pre></li>
  </ol>
  
  <p>Can anyone help?</p>
  
  <p>P</p>