Exchange or Swap Two Images with this Free InDesign Script
You have two images that you want to exchange or swap*. The first question is do you want to exchange the frames themselves, or do you want the frames to stay where they are and just move each image into the other’s frame?
I talked about swapping two objects in this article. So now let’s talk about how to exchange the images and leave the frames where they are.
For example, let’s say I’m laying out this page and I decide to swap two images:

To do this, there’s the slower way (manually) and the fast way (use a free little script). Let me show you the slow, manual way first… alternatively, you can skip this section and get the free script below.
The manual method for swapping two images
First, duplicate the two frames by Option/Alt-dragging them with the Selection tool:

Next double-click one image to select it inside the frame, then cut it to the clipboard. Now select the alternate frame (where you want to put it) and choose Edit > Paste Into… and then do the same with the other image:

You’ll notice that the images are the wrong size and position. So now you can delete the empty frames, select the original frames and choose Object > Fitting > Fill Frame Proportionally. (Or whatever fitting option you desire.)

On the topic of frame fitting
InDesign’s frame fitting options make this process far faster than it would be otherwise. I highly recommend creating and applying an object style that applies frame fitting to the graphic frames before you use the manual or scripted method of swapping images.

However, did you know that sometimes InDesign assigns frame fitting to your frames even if you don’t ask it to? If you place an image by clicking, you typically will not get any frame fitting options applied to it. But if you click-and-drag with the Place cursor (to scale the image), InDesign automatically applies Fitting > Fit Content Proportionally to the frame! Isn’t that interesting?
The fast free script method
OK, now the moment you’ve been waiting for: How can I swap images quickly, with a script? You can download the script here. (And, if you need help installing scripts, read this.)
To run the script, simply select the two frames and double-click the script (or use Quick Apply to run it).
History: Back in 2009, Gerald Singelmann wrote a “startup script” that would do this with a menu command. However, apparently it’s buggy in later versions of InDesign, so an anonymous poster extracted the important code from it. I simply took that code, saved it into a .jsx file and… it seems to work great!
So thanks to Gerald, and thank you to whomever grabbed that helpful bit of code!
* Isn’t “swap” a strange word? It turns out that the etymology of the word is “to strike,” as in clapping hands in a bargain—just as you might shake hands when you say “I’ll give you this for that.”
This article was last modified on July 20, 2021
This article was first published on January 22, 2018
