You designed an InDesign document, using a number of images, and you want to replace those image links with new source files whose names differ from the previous following a predictable pattern. This script will enable you to use InDesign's "Find/Change" dialog box to replace those links.

Example 1: your page layout was achieved using 640-pixels versions of royalty-free pictures from Pixabay, ending with "_640.jpg", and now you made up your mind at least to register to this site in order to be able to download those same pictures in full resolution, the downloaded files have the same name as the previous ones without the "_640" suffix. To replace the links you just need to

open the dialog box Find/Change > Text
type in:
Find what: _640.jpg
Change to: .jpg
Run the script
Select the folder to search in for the links
The script then displays the search results in a window, in many tabs if the result count is high. You can then optionally uncheck some links that you don't want to replace
Validate the window ("OK" or "Replace all checked links" depending on the script version) > Checked replacements are processed.

To proceed the reverse modification, replace all full-res versions with the 640px versions:
Find/Change > Text
Find what: .jpg
Change to: _640.jpg
Run the script, etc.

find change links indd 002 en

Example 2: you still have lower resolution pictures from Pixabay to replace with their full-res versions, but this time you have a mix of 640px, 1280px and 1920px versions (ending with "_640.jpg", "_1280.jpg" or "_1920.jpg"). This time your will have to use:

Find/Change > GREP
FindWhat: _\d+\.jpg
Change to: .jpg
Run the script, etc. (Demo)

Hence the benefit of using the existing Find/Change GREP dialog box that allows you to use the Special Characters icon @ to help you to build your regular expression, because not everybody knows by heart the GREP syntax.

To process the reverse modification restoring the different lower resolutions pictures in place of the full-res ones:

Find/Change > GREP
FindWhat: \.jpg
Change to: _\d+ \.jpg
Run the script, etc.

Notice that in this last specific case "Change to" is also a regular expression, which is not normally expected in InDesign's Find/Change GREP dialog box, but this will enable the script to understand that he must replace the images with others whose ".jpg" extension is preceded by an underscore and one or more digits[1].

The script could then find multiple matching files, if for example your startup image is named chihuahua-2101644.jpg and the search folder contains both chihuahua-2101644_640.jpg and chihuahua-2101644_1920.jpg: for this reason the results are shown in dropdown lists (actually even for single match) in the results window, allowing you to chose before validating the replacements.

The "Include locked layers and items", "Include hidden layers and items" and "Include master pages" options from the "Text" and "GREP" tabs will be taken into account,
The "Case sensitive" option from the Text tab will be taken into account also for the GREP search.

    The new version 13:
  • Better deals with some accented characters on Mac OSX that previously were sometimes not recognized because of the composite unicode (NFD) encoding of the file system (modified after the problem was reported by Andreas Rößner, head of a design studio in Munich).
  • Proposes, if any, to look for the links to replace also in the sub-folders within the selected folder (modified according to a request by Joke Wouters).
  • Unlike in the previous versions, now a single version is provided, displaying a "palette" window that enables you, from within the results tabs, to select each link, showing where it is located, and decide optionally to replace it individually in order to see the difference, or to replace all checked links at once. Tested without problem on many InDesign versions including an old CS5.5.

[1] In example 2 I used the most easy to understand syntax for GREP beginners, but we may also use

Find what: _\d+(\.jpg)
Change to: $1

and the reverse search

Find what: (\.jpg)
Change to: _\d+$1

"Change to" is then an unusual regular expression including a submatch $1 from a previous regex — hybridization correctly interpreted by my script. Entire match $0 also works but will be replaced with its javascript equivalent $&

Add comment

Comments   
Dorine
0 # Dorine 2020-09-23 18:07
I useԁ to be ablе to find good info from your articles.


Here is my wеbsite - m.joker123 downlоad: http://arkbro.info/__media__/js/netsoltrademark.php?d=tinyurl.com%2Fjoker123win52299
Reply
Joke Wouters
0 # Joke Wouters 2019-12-04 21:43
Hi!
This is exactly what I'm looking for except that the script needs to search subfolders also. Can I change that option in the code? Or is that too hard?

I have multiple files to find/change but there divided into subfolder.

Can you help me?
Reply
robinfredericf
0 # robinfredericf 2020-02-25 23:35
I added that option in the new version 13. Best regards — Frédéric Robin.
Reply
Amaury
0 # Amaury 2019-11-29 01:47
Awesome Script! I was looking for this for a long time.

Works great! A very powerful time saver.

Thanks a lot.

Amaury
Reply
robinfredericf
0 # robinfredericf 2017-03-31 16:11
The mediabox popup showing my animated gif demo seems to often crop it depending on your screen size and browser window size, so I also added a (→ Demo) direct link to it.
Note: the text colorization is post-processed on the demo movie to highlight and clarify the regular expression and show what it matches, but you won't see text colorized like that in your InDesign interface when you will use the script.
Reply

Follow Scriptopedia to Social Network

Scriptopedia sur facebook

About Scriptopedia.org

An original idea from Loic Aigon, designed by Eddy.VH. It 's a scripts library for Desktop Publishing Adobe products. Find Javascript for Photoshop, Illustrator, inDesign and Acrobat or ATN scripts ( Photoshop actions ) you need.