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.


I uploaded two versions, the 009 version uses a "dialog" window blocking the application until you cancel or accept the replacement of all checked links, the 011 version uses a "palette" window and may turn out to be less compatible[2] with older CS versions but 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 replace all checked links at once.

[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 by his javascript equivalent $&

[2] On InDesign CS5 I saw the contents of the find-change-links_indd011.jsx palette disappear after the display of the details using the "?" button.

You have no rights to post comments

# 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.


feed-image Follow

Scriptopedia sur facebook


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.