Skip to main content
Known Participant
October 13, 2026
Answered

Object Layer Options: how do I batch images?

According to the documentation, it seems my need must resort to scripting.

Here’s the case: I have an InDesign 2019 document with plenty of images in .psd format, all with the exact same layer structure. From InDesign I want to switch on and off, one layer that’s off in the imported .psd files. The name is exactly the same in all images.

I spotted this post on the forum but can’t make the script work on my side. Either the very brief version or the longer one yield no result.

I’ve also given another script a try, unfortunately it works with instances of the same placed file.

Any help welcome, thank you in advance.

    CORCTON34033231
    CORCTON34033231Correct answer
    Community Expert
    October 13, 2026

    Hi Mathieu,

     

    That script is most likely doing nothing for a simple reason: it only processes placed files whose imageTypeName is "Adobe PDF" (in other words, AI/PDF files). All of your graphics are PSDs, so every one of them is skipped and nothing ever gets changed.

     

    Remove that file-type filter and apply the same graphicLayerOptions change to every graphic instead. A minimal version (edit the layer name in the first line, set onOff to true to show the layer or false to hide it) is:

     

    var layerName = "YourLayerName";

    var onOff = true;

    var g = app.activeDocument.allGraphics;

    for (var i = 0; i < g.length; i++) {

      try { g[i].graphicLayerOptions.graphicLayers.itemByName(layerName).currentVisibility = onOff; } catch (e) {}

    }

     

    Save it as a .jsx file, put it in the Scripts panel (Window > Utilities > Scripts) and run it with the document open. The layer name must match exactly, and graphics that don't contain a layer with that name are simply skipped by the try/catch. Please try it on a copy of the document first.

     

    Hope that helps!

    2 replies

    CORCTON34033231
    Community Expert
    CORCTON34033231Community ExpertCorrect answer
    Community Expert
    October 13, 2026

    Hi Mathieu,

     

    That script is most likely doing nothing for a simple reason: it only processes placed files whose imageTypeName is "Adobe PDF" (in other words, AI/PDF files). All of your graphics are PSDs, so every one of them is skipped and nothing ever gets changed.

     

    Remove that file-type filter and apply the same graphicLayerOptions change to every graphic instead. A minimal version (edit the layer name in the first line, set onOff to true to show the layer or false to hide it) is:

     

    var layerName = "YourLayerName";

    var onOff = true;

    var g = app.activeDocument.allGraphics;

    for (var i = 0; i < g.length; i++) {

      try { g[i].graphicLayerOptions.graphicLayers.itemByName(layerName).currentVisibility = onOff; } catch (e) {}

    }

     

    Save it as a .jsx file, put it in the Scripts panel (Window > Utilities > Scripts) and run it with the document open. The layer name must match exactly, and graphics that don't contain a layer with that name are simply skipped by the try/catch. Please try it on a copy of the document first.

     

    Hope that helps!

    Translate
    Known Participant
    October 13, 2026

    Hi CORCTON34033231,

    Thank you for the swift reply, just tested your script, abracadabra!

    You made my day.

    Translate