Charles, I had some time during lunch. Find attached a new version. The GREP searches now for pairs. The GREP string can be written certainly shorter, but in this case it is more readable. So the GREP will find in the first loop C.E. Darwin, C. E. Darwin, CE Darwin or Darwin, C.E. , Darwin, C. E. and Darwin CE and save the corresponding page. Then it will search for 'DARWIN Charles Erasmus' with a applied paragraph style 'myPStyle' and will insert the page names at the end of the paragraph. If the pargraph had alreday something in brackets, this content will be deleted. So you can run the script multiple times. In the second loop it will find RL Darwin > DARWIN Roqueza Lopena and so on. You can add addtional names or change the GREP expression which determines what is to be found. Because I am only an advanced beginner in Javascript this could maybe be done easier, but this is my way for today . main (); function main() { var curDoc = app.activeDocument; var allPages = curDoc.pages; // [ GREP-Querie, special paragraph ] var searchList = [ [ "(?i)((C\\. ?E\\.|CE) Darwin)|(Darwin, (C\\. ?E\\.|CE))", "DARWIN Charles Erasmus" ], [ "(?i)((R\\. ?L\\.|RL) Darwin)|(Darwin, (R\\. ?L\\.|RL))", "DARWIN Roqueza Lopena" ], [ "(?i)((C\\. ?R\\.|CR) Darwin)|(Darwin, (C\\. ?R\\.|CR))", "DARWIN Charles Robert" ], ]; // loop through the searchList for ( var s = 0; s < searchList.length; s++ ) { app.findGrepPreferences = null; app.findGrepPreferences.findWhat = searchList [0]; var pNumbers = new Array(); // loop through all pages for ( var p = 0; p < allPages.length; p++ ) { var curPage = allPages ; var tfs = curPage.textFrames; // loop through all textframes on the current page for ( var t = 0; t < tfs.length; t++ ) { var tf = tfs ; if ( tf.contents != "" ) { var res = tf.findGrep(); if ( res.length > 0 ) { pNumbers.push( curPage.name ); break; } // if } // if } // tfs } // allPages var pageString = pNumbers.join( " " ); alert ( searchList [1] + ": " + pageString ); app.findGrepPreferences = null; app.findGrepPreferences.findWhat= searchList [1]; app.findGrepPreferences.appliedParagraphStyle = curDoc.paragraphStyles.itemByName( "myPStyle" ); var result = curDoc.findGrep(); var para = result[0].paragraphs[0]; // if the paragraph has already content in '[…]' this content will be deleted if ( para.characters[-2].contents == "]" ) { app.findGrepPreferences = null; app.findGrepPreferences.findWhat = " +\\[[^\\]]+\\]"; app.changeGrepPreferences.changeTo = ""; para.changeGrep(); } para.insertionPoints[-2].contents = " [" + pageString + "]"; } // searchList } // main
... View more