 <p>To consider page 1 only…</p> <pre><code>var main = function(){ var doc = app.properties.activeDocument, finds,n; app.findTextPreferences = app.changeTextPreferences = null; app.findTextPreferences.findWhat = "#"; if ( !doc ) return; finds = doc.findText(); n = finds.length; while (n-- ) { finds[n].parentTextFrames.length &amp;&amp; finds[n].parentTextFrames[0].isValid &amp;&amp; finds[n].parentTextFrames[0].parentPage.id==doc.pages[0].id &amp;&amp; finds[n].contents = "no: " + String(n+1); } }; main(); </code></pre>