Copy link to clipboard
Copied
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
}
}
});
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
There is no imageColorSpace - but there is a space:
https://www.indesignjs.de/extendscriptAPI/indesign-latest/#Image.html
|
space |
readonly |
The color space. |
Can be "RGB", "LAB", "CMYK", "PANTONE" - in VB - in JS it can be lowercase.
Copy link to clipboard
Copied
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".
Copy link to clipboard
Copied
InDesign is unable to import MultiChannel:
Copy link to clipboard
Copied
Hi Robert, There’s also Grayscale + Spot, RGB + Spot, etc., but the graphic object does not have the .space property, so that begs the question, why is an RGB image a problem, but an RGB graphic is not?
Copy link to clipboard
Copied
Not sure what do you mean?
You can get "space" from the applied fill / stroke / effects swatch / color?
Copy link to clipboard
Copied
But , not from something like a placed PDF, ID, or AI file, which could have objects with different spaces inside.
Preflight can get everything
Copy link to clipboard
Copied
But , not from something like a placed PDF, ID, or AI file, which could have objects with different spaces inside.
Preflight can get everything
By @rob day
Not sure how?
I've placed Quadtone and Bitmap - exported as PDF then placed it back - only info I can get is:
But more info is in the Links Panel:
Now - how to get this info - which Swatch is used where - in which linked file?
Copy link to clipboard
Copied
Now - how to get this info - which Swatch is used where - in which linked file?
By @Robert at ID-Tasker
OK, Find Colour works:
So it's doable...
Copy link to clipboard
Copied
Or not...
JS:
https://www.indesignjs.de/extendscriptAPI/indesign-latest/#Document.html#d1e49551__d1e54225
VB:
It looks like it returns NUMBER of instances - not a list / an array?
Copy link to clipboard
Copied
OK, the workaround would be to create a new document - then place this link - in this case PDF (*) - and check what's new on the Swatches list:
Place or just Copy&Paste.
(*) works with PSD as well - so will work with any link.
Copy link to clipboard
Copied
Keeping in mind that @code_seeeeeker is trying to find RGB objects, not Spot colors, he would not be able to get a selection‘s color space if the selected object is a PDF, AI, INDD, EPS. So this is an example of a placed PDF (that looks like an image):
.space for the selection returns an error:
var s = app.activeDocument.selection[0];
$.writeln(s.space)
//returns Object does not support the property or method 'space'
$.writeln(s.constructor.name)
//returns PDF
Copy link to clipboard
Copied
@code_seeeeeker , could check for RGB color inside of PDFs, etc. via a preflight rule. Something like this which would catch RGB inside of PDFs, linked RGB images, or native document RGB color:
if (checkForRGB()) {
alert("This Document Contains RGB color")
} else {
alert("No RGB color")
}
/**
* Checks Document for RGB Color
* @ return true if RGB objects are found
*
*/
function checkForRGB(){
var d = app.activeDocument
//Make a new Preflight Profile
var pf = makePreflight("TestNoRGB");
var cs = makeRule(pf, "ADBE_Colorspace")
cs.flag = PreflightRuleFlag.returnAsError;
var csNoRGB = cs.ruleDataObjects.itemByName("no_rgb")
csNoRGB.properties = {dataType:RuleDataType.BOOLEAN_DATA_TYPE, dataValue:true}
d.preflightOptions.preflightOff = false;
d.preflightOptions.preflightWorkingProfile = pf;
var pfp = app.preflightProcesses.add(d, pf)
pfp.waitForProcess();
if (pfp.processResults.length > 6) {
return true
} else {
return false
}
}
/**
* Makes a new Preflight
* @ param preflight name
* @ return the new preflight
*/
function makePreflight(n){
if (app.preflightProfiles.itemByName(n).isValid) {
return app.preflightProfiles.itemByName(n);
} else {
return app.preflightProfiles.add({name:n});
}
}
/**
* Makes a new Preflight Rule
* @ param preflight name
* @ param the preflight rule constant name
* @ return the new preflight rule
*/
function makeRule(pf, n){
if (pf.preflightProfileRules.itemByName(n).isValid) {
return pf.preflightProfileRules.itemByName(n);
} else {
return pf.preflightProfileRules.add(n);
}
}
Copy link to clipboard
Copied
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more