You should tell us what platform/language you want to use.
I also hate to be the less-than-useful responder, but there are many sample scripts that come with your InDesign/Creative Suite disks. There are some find/change examples that you can copy/paste and change your specific info. That should get you started, then you can string a couple operations together for your script.
Oops sorry forgot to mention a few things.
1. Windows XP
2. InDesign CS 4
I saw the sample scriipts but wasn't entirely sure what all it it was changing.
Usually I can pick code apart and alter it but the code was a little tough to decipher.
I am used to using PC Macros in Office or the ones like in Photoshop where you can "hit record"
I'd sure love to be able to hit a record button in InDesign As it is, writing even the smallest script boils down to a good reference and some preparing for the unexpected.
app.findTextPreferences = null;
app.changeTextPreferences = null;
Now that was easy, wasn't it. "app" holds, at the start of the script, a pointer to the current running 'host' application: the program actually running the script. From within InDesign, it's InDesign
Notice the semi-colon ending each line. JS does not care about hard returns but the semi-colon tells it the previous command line is finished. You can also write everything on a single line and without spaces inbetweem, like this
but let's keep things readable, shall we.
You can already run this little script, and you'll see that it indeed clears out the Find/Replace dialog. Try it: put "something" in the Find Text, and "Italic" in the Change to Format. Then run the script. If you call up the Find/Change dialog again, you'll see it's empty.
You mentioned searching and replacing text. Well, let's put it in the proper Find and Replace fields. Documentation says, findTextPreferences has a property 'findWhat' -- the text to find.
app.findTextPreferences.findWhat = "what";
-- and changeTextPreferences has a property 'changeTo' -- the text to change:
app.changeTextPreferences.changeTo = "to";
You can run this script, but it won't seem to replace a thing (yet). But... if you call up the Find/Change dialog now, you'll see these texts in the Find/Change edit fields. It worked!
Let's do something. Setting values to properties is one thing, but to actually perform an action, you need an object that performs it and the command to do it (these commands are called 'methods').
As from within the User Interface, you need to provide a find scope for the operation: application-wide ("All Documents"), document-wide ("Document"), current story only, or selection only. Supposedly, you want it document-wide. Checking the Document object shows this indeed has a method 'changeText', and it has one optional parameter. You can forget about the parameter for now, its default value ("false") is good at the moment. So the full command will look like "Document.changeText()".
"Document" itself is a kind of object, defined by InDesign (a regular InDesign document, opened in the application). Since you can have more than one document, you'll need to state the actual document that you want to replace in. InDesign can do the replace in any document (that's opened), even if it's not the active one, but to refer to the active one -- the one in front of you now -- it has a shortcut called 'activeDocument'. That's an Application property (and "app" is the current application), so it sounds like this is the proper line:
If you want to add more find/changes, you don't have to clear the preferences stuff after the first time, since all you are changing is the 'findWhat'/'changeTo' strings, and the rest will stay empty.
There it is: your first script.