title: Reference a textFrame in InDesign by part of its name
body: <p>I've run into an interesting quandary:  How can I reference a specific textFrame within InDesign CS6 if I only know PART of its name?  I have this bit of code:</p>
  
  <pre><code>var otherOverTable = document.layers.item("Spec Sheet").textFrames.item("&lt;Other Printed ItemsYESNOOv&gt;").tables.item(0);
  var outputTable = document.layers.item("Spec Sheet").textFrames.item("&lt;OUTPUT&gt;").tables.item(0);
  </code></pre>
  
  <p>This code does not work.  I'm pretty certain it's due to the fact that the specific textFrames that have names surrounded by "&lt;" and "&gt;" signs are generated automatically by the text within those frames.</p>
  
  <p>Beyond just renaming those textFrame objects before running the script, what can I do?  Is there some way I could reference the first one, for example, by saying something like, "Get the textFrame which has 'Other' as part of its name"?  I cannot reference it by index number as that will be different each time I run the script.</p>
  
  <h2>Edit</h2>
  
  <p>I've got this bit of code to work, thankfully:</p>
  
  <pre><code>var otherOverTextFrame = findTextFrame(document, "Other");
  var outputTextFrame = findTextFrame(document, "OUTPUT");
  
  function findTextFrame(document, searchStr) {
  var textFramesArray = document.textFrames.everyItem().getElements();
  for (var i = 0; i &lt; textFramesArray.length; i++) {
      if (textFramesArray[i].tables.item(0).isValid) {
          if (textFramesArray[i].tables.item(0).cells.item(0).contents.indexOf(searchStr) != -1) {
              return textFramesArray[i];
          }
      }
  }
  }
  </code></pre>
  
  <p>This returns an <code>[object TextFrame]</code>.  I think that's what I need, but I'm having trouble figuring out how to reference it.  For example, I need to change the contents of a certain cell within the table within that textFrame.  This code, however, does not work:</p>
  
  <pre><code>var otherOverTable = document.layers.item("Spec Sheet").otherOverTextFrame.tables.item(0);
  </code></pre>
  
  <p>How do I go about getting over this last hurdle?</p>