Question
Event Listener to check RGB Image(s) in InDesign and illustrator
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
}
}
});
