Skip to main content
fabianmoronzirfas
Known Participant
March 24, 2013
Question

batch-find-and-replace.jsx

  • March 24, 2013
  • 3 replies
  • 24274 views

Hi there, I wrote a batch-processing script for find change queries and thought I share it with you. You can get it over here 

You can process GREP, TEXT, GLYPH and OBJECT searches. 

Purpouse

While creating books in InDesign with several documents we always come across some find change queries that need to be used again, and again, and again. To make this process easier you can just grab their names and put them into a list. The script will than try to process all your queries in one click. 

prerequisites

  1. make sure you have a toml file.
  2. make sure the toml file is next to the script.
  3. make sure the toml file has the right formatting (see below in section TOML)
  4. if you want the script to autoexecute (without toml file selection), make sure the .toml file has the right name: "batch-find-and-replace.toml"
  5. make sure your fcqueries work right

Usage

  • Place the script and the toml file into your Scripts Panel Folder 
  • define some find and change queries and save them via the InDesign dialogue.
  • get the xml file names and add them to the "batch-find-and-replace.toml" file in the right spot. text search goes into text.files = [], grep search goes into grep.files = [] and so on. Make shure to remove the .xml from the filename. You can find these files on:
    • Mac OS Users[username]\Library\Preferences\Adobe InDesign[Version][Language]\Find-Change Queries[query type] 
    • Windows XP Documents and Settings[username]\Application Data\Adobe\InDesign[Version][Language]\Find-Change Queries[query type] 
    • Windows Vista and Windows 7 Users[username]\AppData\Roaming\Adobe\InDesign[Version][Language]\Find-Change Queries[query type] 
  • the .toml file should be located next to the script file and have the  appropriate name (batch-find-and-replace.toml). If so the script wont ask for the toml file and process the data right away. If not the script will ask you to select the .toml file.
  • Thats it. Watch the magick happen.

TOML

Tom's Obvious, Minimal Language is a simple markup language that makes settings human readable. It is still in development and may change a lot. But still. It is a pretty easy language and can be learned by anyone.
The basic toml filer looks like this: 

# these are the basic settings
# the MUST be there
do_text = true
do_grep = true
do_glyph = true
do_object = false
# now the file names
# they have to be in one line
# the toml specs say you can break lines in arrays
# but the toml.js does not allow that at the moment
[text]
files = ["my_first_text_find_and_change","another one"]
[grep]
files = ["somegrepsearch", "find tabs", "something else"]
[glyph]
files = []
[objects]
files = []

MUST HAVE Settings

With the do_text, do_object, do_grep and do_glyph you can define if the script should do the corresponding find and replace. Set them to true or false.

CAN HAVE Settings


In the [text],[grep],[glyph] and [objects] areas you can define the filenames that should be processed. Make sure the filenames are written right. If there is a file mentioned that does not exist the script will throw an error. It will try to process all the .xml files it can find.
!IMPORTANT! you MUST remove the .xml from the filename in the list as shown above.

The Script is here --> https://raw.github.com/...find-and-replace.jsx

The basic .toml file here --> https://raw.github.com/...ind-and-replace.toml

The Readme here --> https://github.com/...lob/master/README.md

And the whole package here --> https://github.com/...e/archive/master.zip

This topic has been closed for replies.

3 replies

Participant
January 12, 2022

Hi! After almost a decade this is still a very usable script, but I just discovered a terrible error that it can produce if not used carefully:

If you execute a saved Find/Change that calls for a replacement Character Style that does not exist in an InDesign document, the found text will simply be deleted. There is neither message about error nor the batch stops.

May 20, 2014

Great script, it worked perfectly with grep, text, glyph, not only worked with OBJECTS, because I do the same operation and does not work. Can you give me a hand? Thank you.


In arquivo.toml is thus:

# These are the basic settings

# The MUST be there

do_text = true

do_grep = false

do_glyph = false

do_object = true

do_all_docs = false

# Now the file names

# They have to be in one line

# TomL the specs say you can break lines in arrays

# But does not allow the toml.js que momento

[text]

files = ["_OVER_BLACK_TXT", "_OVER_CORPROF_TXT"]

[grep]

files = []

[glyph]

files = []

[object]

files = ["_OVER_BLACK_FILL", "_OVER_BLACK_STRK"]

This is the image of the Scripts Panel folder:

May 20, 2014

It was not working because the. Jsx on line 1289, was missing the character "s" in the syntax. Instead of app.findObjectPreferece is to be app.findObjectPreferences, was missing the "s" in the word Preferences. I hope I have contributed to other users. Greetings!

fabianmoronzirfas
Known Participant
July 15, 2014

Hi Turtles,

thanks for the hint. I did not receive a notification for your reply. Sorry for the delay I will fix this right away.

Cheers

Fabian

Participating Frequently
April 12, 2013

Good morning,

Excellent script, works like a charm ! Great job.

I was wondering if I could use this script for all currently open documents, instead of only the active one?

Right now, when I run the script, it only does the job on the currently active document. The other documents that are also open in InDesign, are not being edited. Thing is, I would like to use this for 300+ buttons every 2 weeks. Those buttons are made in seperate InDesign files. To click the script on every document is not an option, then I could just run the actual queries instead.

Would be great if this is possible, to apply this script with one click on all open documents.

Can you help me in the right direction? Thanks !

Greets,

Mirna

fabianmoronzirfas
Known Participant
April 12, 2013

Good morning Mirna,
cool you dig this. I updated the script so it can work on all open documents. In the .toml file is a new "must have setting" called

do_all_docs = true 

Set it to true if you want to process all open documents.
Let me know if this works for you.

Cheers

:Fab

P.S. The download link in the description points to the new version.

Participating Frequently
April 12, 2013

Thank you so much for the fast response.

Unfortunately I get an error.

There was an error while trying to process the "MPP_TITLE_SDF.xml"

Please make shure (sure) it exists and is at the right spot

Error: changeText

After clicking away this error for 8 times (I have 4 docs open, each doc has to execute 2 queries) only the active document is changed, the others aren't edited at all.

Tried both text and grep, they gave me the same errors on "changeText" and "changeGrep". In the .toml file ".xml" has been removed.

Thank you for your time, I really appreciate it.

Greets,

Mirna

EDIT: I changed "true" to "false" on the do_all_docs and I get no error. So it's only when this setting is set to "true".