The first part of your query already exists: http://www.kahrel.plus.com/indesign/chain_queries.html, though I'm not sure I entirely understand what you mean with "stores the spot" and where exactly the corresponding replace pattern comes in. The script's name is "chain_queries.jsx", which is slightly misleading as it can be used for more things than just chaining, but there you go.
Here's a quick guide:
1. Create a GREP query in the Find/Change dialog and save it.
2. Start the script linked above, select your query in the list, make sure you check "Test mode", and press OK.
3. The script finds everything matched by the query, sorts the results, removes duplicates, and writes the results in a new document.
The second part of your request, batch replacing the list, is lying around somewhere but I haven't found it yet. Anyway, from your post it's not clear what the items in your list should be changed with -- in other words, where your "corresponding replace patterns" are.
Edit: > I'm not sure ... where exactly the corresponding replace pattern comes in
Never mind -- I wasn't awake yet. Will dig up the replacer.
First I want to thank you for the fast response and apologize my bad english. I will try to describe my problem a bit more accurate. Initial point is a typographically horrible formated document. After 10 seconds of scaring on the part of the stylist, he want to start a script wich automaticly runs serveral GREP's, that found the accidental points in the document and list them down in a listelement. Everyone of the several GREP's has its own replacepattern. They are organized in a SQL-Database. After the list is created, the stylist steps along the list, got a selection around the spot in the text and makes a decision if the found spot shoud have a replacement or not. This could be done for example with a checkbox. After hitting the "replace now" button the script process the well proven list, that the replacement pattern, which corresponds to the GREP that found the spot, should be applied.
I hope the process is more clear now. Thanks again for your support.
If I understand correctly, you have a list with GREPs, both the find and the change expressions, and these should be run against a document interactively. But do you need a script for that? You might as well do that in the interface.
There's a quick way to load selected text into the "Find what:" and "Change to:" fields of the Find/Change dialog: define some shortcut keys in the keyboard shortcut editor. So you would get the expressions from your database into an InDesign document (a table would be convenient). Then select the GREP expression and press the shortcut you defined to place the text selection into the "Find what:" field. Do the same with the "Change to:" expression. Then use the Find and the Change or Change/Find buttons.
>Is there an array behind changeGrep which stores the spots? If so, is there any way to manipulate this one?
findGrep() creates an array of found items, changeGrep() returns an array of changed items. To manipulate either of these arrays, do something like this:
app.findGrepPreferences = null; // reset the Find/Change dialog
app.findGrepPreferences.findWhat = "\\d+"; // set some search pattern
myFound = app.documents.findGrep ();
This creates an array of all whole numbers in the active document, which you can process in the normal way:
for (var i = 0; i < myFound.length; i++)
Using find and change GREP in a script is a bit more involved. One thing is that you need to set the options (include footnotes, include locked layers, etc.). To find out more about scripting in general and scripting GREP in particular, consult Adobe's documentation and/or http://oreilly.com/catalog/9780596802523/