Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

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

Participant ,
Sep 20, 2024 Sep 20, 2024

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
        }
    }
});

 

TOPICS
Scripting
1.0K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 20, 2024 Sep 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.

 
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Sep 20, 2024 Sep 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.

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Sep 20, 2024 Sep 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".

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Sep 20, 2024 Sep 20, 2024

RobertatIDTasker_0-1726842218757.png

 

InDesign is unable to import MultiChannel:

RobertatIDTasker_0-1726842311096.png

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 20, 2024 Sep 20, 2024

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?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Sep 20, 2024 Sep 20, 2024

@rob day

 

Not sure what do you mean? 

 

You can get "space" from the applied fill / stroke / effects swatch / color? 

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 20, 2024 Sep 20, 2024

But , not from something like a placed PDF, ID, or AI file, which could have objects with different spaces inside.

 

Preflight can get everything

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Sep 20, 2024 Sep 20, 2024
quote

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:

 

RobertatIDTasker_0-1726859468979.png

 

But more info is in the Links Panel:

 

RobertatIDTasker_2-1726859522327.png

 

Now - how to get this info - which Swatch is used where - in which linked file?

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Sep 20, 2024 Sep 20, 2024
quoteNow - how to get this info - which Swatch is used where - in which linked file?

 

By @Robert at ID-Tasker

 

OK, Find Colour works:

 

RobertatIDTasker_1-1726859897619.png

 

RobertatIDTasker_2-1726859909991.png

 

So it's doable...

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Sep 20, 2024 Sep 20, 2024

Or not...

 

JS:

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

RobertatIDTasker_0-1726860042901.png

VB:

RobertatIDTasker_1-1726860098434.png

 

It looks like it returns NUMBER of instances - not a list / an array?

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Sep 20, 2024 Sep 20, 2024

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:

 

RobertatIDTasker_0-1726861280635.png

 

Place or just Copy&Paste.

 

(*) works with PSD as well - so will work with any link.

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 20, 2024 Sep 20, 2024

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

 

Screen Shot 6.png

 

.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

 

 

 

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 20, 2024 Sep 20, 2024

@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);
    }
}

 

 

Screen Shot 7.png

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Sep 20, 2024 Sep 20, 2024
LATEST

@rob day 

 

Yes, there is no space property for vectors.

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines