is now part of CreativePro.com!

Exchange or Swap Two Images with this Free InDesign Script

12

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:

how to exchange 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:

duplicate images

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:

exchanging images

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

after fitting images

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.

object style with frame fitting

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

David Blatner is the co-founder of the Creative Publishing Network, InDesign Magazine, CreativePro Magazine, and the author or co-author of 15 books, including Real World InDesign. His InDesign videos at LinkedIn Learning (Lynda.com) are among the most watched InDesign training in the world.
You can find more about David at 63p.com

Follow on LinkedIn here
  • Masood Ahmad says:

    Worked like a charm. Thanks for sharing it.

  • Gerald’s script is a “must have” on any machine I work on, and I’ve featured it on one of my “must-have” videos on Youtube.
    Gerald’s startup script can be called upon by selecting the two images and right clicking to show the contextual menu, and then select the option “swap images” at the bottom of the contextual menu, whereas the newer script has to be run from the javascript panel or quick-apply panel.
    It’s worth noting that the newer script hasn’t fixed or replaced the old script; it’s only lines 44-59 of Gerald’s original script that have been copied and made into its own script purely for the purpose of swapping images, whereas Gerald’s script also allows objects to be swapped as well.
    That said, I’ve never experienced any issues running Gerald’s script and continue to run it on ID CC 2018 running on my High Sierra Mac. The error may have been to a particular version ID, but I can safely say it works fine on my machine.

    • Tobias Wantzen says:

      I can second Colin. Gerald’s original script works perfectly over all versions of InDesign up to CC2018 (Mac OS 10.12.6) and I never faced an error with it. Where does the info come from, that Gerald’s script is buggy in newer versions of ID?

  • Kasyan says:

    I support Colin: the script does work for me beautifully in InDesign CC 2018 on Windows 10.
    David, what do you mean by the term ‘buggy’? Do you get an error message on start up?
    I am aware of the bug in the Russian version of InDesign CC 2015 (maybe it’s also present in later versions, but I haven’t tested it yet) which doesn’t understand locale independent strings in scripts (they are used, in particular, to reference menu items). In this version the script produced the ‘object is invalid’ error on line 38 while trying to add a separation line in the context menu.
    Alternatively, we can swap images from Bridge using this script. https://goo.gl/RpTMY3 Make sure to select an image with the selection tool (black arrow) in InDesign — the contents selection tool (white arrow) won’t work.

  • Amit Gupta says:

    Really worked perfectly on Mac with ID CC2018.

    Thanks for sharing.

  • Simon Kemp says:

    Has worked perfectly for me on Windows 7 from CS4 right up to CC2018 (I missed 5.5). Very useful.

  • Kristin says:

    Thanks a lot for sharing!

    Unfortunately it won’t work in my case:
    ID CC 2018 (Version 13.0.1, german) Mac OS High Sierra (Version 10.13.3)

    Running the script it shows me: Java Script Error; No. 30477; invalid parameter.

    Could be, that the script stops in ligne 12?

    • Hendrik says:

      Hello, Kristin,

      I had the problem too. You can easily solve it by moving the jsx file to the Scripts Panel folder of Indesign, e.g. under Samples/Javascript.

      Start InDesign, show window utilities/scripts (Ctrl+Alt+F11). Select two images, double click the script.

  • Kristen says:

    I wish this worked for me. I did all the steps and when it’s installed in the scripts folder, and hovered over in the scripts panel in InDesign, it tells me “This file is not executable by any supported script language.” I can’t even move it out of the user folder. I can only delete it.

  • Joni says:

    I am also getting the “This file is not executable by any supported script language.” error. And a search on google gets me 1 result – this page.

    I opened the script panel and navigated to Application javascript FindChangeByList script. The support file is listed, but is greyed out with the little information “i”. When you hover over the file name, the above error is shown.

    So I moved the FindChangeByList.jsx to my user indd script folder and the error is the same. Is there something in the sample file that needs to be altered the first time to be used?

    I didn’t even get to try to make changes and screw up the code yet… lol

    • Joni says:

      Oh duh. My story (and I’m sticking to it) is my ignorance on this one is due to the massive amounts of cold medicine I am on… The support file is listed there in the panel, but you don’t need to click on that. Right above the support file, is the SCRIPT. Double click that and you are in business.

  • camilo chaves says:

    Hello everybody. Thanks for the script, I took it and I noticed it only works if you select the frames, it does not work if you select the images, selecting the frames is sometimes imposible, for example if they are behind the image or if they are in a Master. So I Improved the script and now it works if you select the frame holding the image OR the image itself. The new script is here and of course you can take it and put it in this page if you want:
    http://acolombiantraveler.com/swap-images-indesign-script/

  • >