Skip to main content
Inspiring
September 20, 2024
Question

Event Listener to check RGB Image(s) in InDesign and illustrator

  • September 20, 2024
  • 2 replies
  • 914 views

Hi,

I'm trying to create an Event Listener to use in Adobe InDesign, to alert me if the document contains RGB images. I tried this, but this is not working. Can you please correct the code for me. Also I want the same listener for Illustrator as well.

//DESCRIPTION: Event Listener to check if the document contains any RGB images
#targetengine "save"
app.addEventListener("beforeSave", function () {
    var doc = app.documents[0];
    for (var i = 0; i < doc.allGraphics.length; i++) {
        try {
            var img = doc.allGraphics[i];

            // Only check raster images (e.g., JPEG, PNG, TIFF)
            if (img.constructor.name === "Image") {
                if (img.imageColorSpace === ColorSpace.RGB) {
                    alert("Document contains RGB image(s). Please convert them to CMYK!");
                    break;
                }
            }
        } catch (e) {
            // Handle errors silently
        }
    }
});

 

2 replies

Robert at ID-Tasker
Legend
September 20, 2024

@code_seeeeeker 

 

There is no imageColorSpace  - but there is a space:

 

https://www.indesignjs.de/extendscriptAPI/indesign-latest/#Image.html

 

space

String

readonly

The color space.

 

Can be "RGB", "LAB", "CMYK", "PANTONE" - in VB - in JS it can be lowercase.

 

Robert at ID-Tasker
Legend
September 20, 2024
quote

@code_seeeeeker 

 

Can be "RGB", "LAB", "CMYK", "PANTONE" - in VB - in JS it can be lowercase.

 

By @Robert at ID-Tasker

 

Sorry, my bad. There is no "PANTONE" - in the code of my old tool PhotoManager, I'm checking last 4 characters for "TONE" - and it's not from PANtone - but from DUOtone and MONOtone and others ending with "tone".

 

Robert at ID-Tasker
Legend
September 20, 2024

 

InDesign is unable to import MultiChannel:

 

rob day
Community Expert
Community Expert
September 20, 2024

Hi @code_seeeeeker , there is no .imageColorSpace property for an image or graphic object—you should see the error if you remove the try statement.

 

If you want to check for RGB objects, I think you would have to consider more than images, something like a placed PDF or AI could have a mix of color spaces. The better approach might be to script a preflight profile that checks for any RGB—if you haven’t scripted preflight I can post an example.