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

Javascript to warn if an RGB file is linked to open InDesign document.

Participant ,
Oct 25, 2023 Oct 25, 2023

Hi all,

 

I use a javascript that exports 2 or 3 flavors of pdf.  Works great.  I'd like to add an alert that flags any linked rgb file (tiff).  And if clear, will just pass to the next process. So alerts if RGBs linked, no alert if CMYKs are linked.

Below is what I have, but it always says that there is no RGB, whether or not rgb is linked.  

 

// Function to run a system command and capture the output
function runShellCommand(command) {
try {
var process = new Process;
process.exec(command);
process.waitFor();
return process.stdout;
} catch (e) {
return null;
}
}

// Function to check the color mode of a linked image
function isRGBImage(imagePath) {
var exifToolCommand = 'exiftool -ColorSpace -n -T -q -q "' + imagePath + '"';
var colorProfileInfo = runShellCommand(exifToolCommand);

if (colorProfileInfo) {
return (colorProfileInfo.indexOf("RGB") !== -1);
}

return false;
}

var doc = app.activeDocument;
var linkedImages = doc.links;

var rgbImagesFound = false;

for (var i = 0; i < linkedImages.length; i++) {
if (isRGBImage(linkedImages[i].filePath)) {
rgbImagesFound = true;
alert("RGB image found: " + linkedImages[i].name);
}
}

if (!rgbImagesFound) {
alert("No RGB images found in the document.");
}
~Roy
TOPICS
Scripting
1.5K
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

correct answers 3 Correct answers

Community Beginner , Oct 26, 2023 Oct 26, 2023

Thanks for the suggestion to convert all to a prescribed cmyk. However, clients and pubs all have specific profiles that would require many more

job options and the potential for mismatch. Yes our artist should look for errors in the pre flyt but this script would act as a safety. 

if I get something to work I'll post the code and you all can give it a try. The export various PDFs routine is a real time saver. 

Translate
Community Expert , Oct 26, 2023 Oct 26, 2023

So the CMYK files get saved with no embedded profile, and the InDesign PDF Export Color Conversion is set to No Conversion? Do your retouch artists make color corrections after the conversion to CMYK?

 

Can you post the full script?

 

Translate
Participant , Oct 26, 2023 Oct 26, 2023

All the CMYK images are tagged, and yes the job options are set to No Conversion.  Here's the scriot as it stands.  You will need to replace preset1-3 with joboptions within your export sets. There is a spot at the top of the code that I commented out indicating where the "break" might go?

 



d = app.activeDocument;

if (checkForRGB()) {
alert("Document contains RGB color");
//Insert a break here?

} else {
//alert("No RGB color")
}

/**
* Checks Document for RGB Color
* @ return true if RGB objects are found
...
Translate
Community Expert ,
Oct 26, 2023 Oct 26, 2023

Hi @RoyBoySolorio ,  If you want your PDF to Export as all CMYK, why not simply set the Export>Output Destination to a CMYK profile? That would convert all RGB color to CMYK in the exported PDF.

 

On your code, if I comment out the try in your runShellCommand function I always get an error—Process does not have a constructor. So colorProfileInfo is always returning null.

 

A more reliable approach might be to check for RGB color using InDesign’s preflightProfile object.

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 Beginner ,
Oct 26, 2023 Oct 26, 2023

Thanks for the suggestion to convert all to a prescribed cmyk. However, clients and pubs all have specific profiles that would require many more

job options and the potential for mismatch. Yes our artist should look for errors in the pre flyt but this script would act as a safety. 

if I get something to work I'll post the code and you all can give it a try. The export various PDFs routine is a real time saver. 

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 ,
Oct 26, 2023 Oct 26, 2023

all have specific profiles that would require many more job options

The conversion to CMYK should always be to Document CMYK—the PDF/X-1a default. You wouldn’t want to find an RGB image and convert it to a conflicting CMYK profile in Photoshop, so the Destination would always be DocumentCMYK.

 

Try this preflight function. It will check for any RGB color:

 

if (checkForRGB()) {
	alert("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 80.png

Screen Shot 83.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
Participant ,
Oct 26, 2023 Oct 26, 2023

rob day, this works great.  Is there a way to "break" in the script or exit the script after the rgb error dialog box is closed? 

~Roy
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 ,
Oct 26, 2023 Oct 26, 2023

The checkForRGB() function returns true or false, so you don’t need the alerts. I assume if there is no RGB color you want to make a PDF? So you can check if checkForRGB() returns as false (no RGB color) and add your PDF routine. if it returns true you can throw up a dialog and the script ends.

 

 

 

if (!checkForRGB()) {
	//Add function for the Export here
} else {
    alert("There’s RGB Color Now What?")
}

 

 

 

What will you do if there are RGB images? Open the images into Photoshop and convert to CMYK? What profile will you convert to?

 

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
Participant ,
Oct 26, 2023 Oct 26, 2023

Glad to elaborate,

 

Maybe this is unorthodox, no judging, we manage all CMYK within the Retouching department.  The Assembly artists just push managed images through for loose color.  News, 280, 300, 320dmax,  spec'd CMYK or Greyscale goes unaltered, into the PDF. We have an epson rip that errors when an RGB is linked, but on rare occasions RGB will get through, converting in the rip, with odd effects.  Mostly bad and obvious.  

The other chore creates 3 pdfs from the same mechanical, a High, Medium and Low res PDF for various needs.  We have an InDesign script that performs that, calling on the various joboptions, which creates the 3 pdfs.  All good.

What your script does is, prior to making the pdfs, evals the doc and throws out the warning/alert when RGB is detected.  But when the alert panel is closed, it wants to continue with making the pdfs. 

 

I can cancel, which is ineligant with a scarry javascript error, but I would perfer that once the warning panel is closed, just returns to the doc, where the artist updates the link and restarts the script.

 

What do you think?

~Roy
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 ,
Oct 26, 2023 Oct 26, 2023

So the CMYK files get saved with no embedded profile, and the InDesign PDF Export Color Conversion is set to No Conversion? Do your retouch artists make color corrections after the conversion to CMYK?

 

Can you post the full script?

 

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
Participant ,
Oct 26, 2023 Oct 26, 2023

All the CMYK images are tagged, and yes the job options are set to No Conversion.  Here's the scriot as it stands.  You will need to replace preset1-3 with joboptions within your export sets. There is a spot at the top of the code that I commented out indicating where the "break" might go?

 



d = app.activeDocument;

if (checkForRGB()) {
alert("Document contains RGB color");
//Insert a break here?

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

// BS"D
// All rights reserved (c) 2015 by Id-Extras.com
// Free to use and modify but do not delete this copyright attribution.
// This script will export 2 pdfs of the current document
// Choose the PDF presets by altering their names below
// The second PDF gets a suffix added to its name.
// Modify the line below beginning name2 = to change the suffix.
// For more InDesign scripts: www.Id-Extras.com
// XYZ modified for 3 type pdfs...also holds all characters but removes .indd
d = app.activeDocument;
// Here you can choose the PDF preset
preset1 = app.pdfExportPresets.itemByName("HiRes_joboption");
preset2 = app.pdfExportPresets.itemByName("MedRes_joboption");
preset3 = app.pdfExportPresets.itemByName("LoRes_joboption");
if (!(preset1.isValid)){
alert("One of the presets does not exist. Please go to Vol1-Photoshop_Illustrator_InDesign_Acrobat_Stuff/AcrobatJobOptions_B/for actions, and load them into your setting folder");
exit();
}
//if (!(cancel)){alert("PDFs will not be created. Whaaa");
//exit();
//}
if (d.saved){
thePath = String(d.fullName).replace(".indd", "") + ".pdf";
thePath = String(new File(thePath).saveDlg());
}
else{
thePath = String((new File).saveDlg());
}
thePath = thePath.replace(/\.pdf$/, "");
name1 = thePath+".pdf";
// Here you can set the suffix at the end of the name
name2 = thePath+"_MR.pdf";
name3 = thePath+"_LR.pdf";
d.exportFile(ExportFormat.PDF_TYPE, new File(name1), false, preset1);
d.exportFile(ExportFormat.PDF_TYPE, new File(name2), false, preset2);
d.exportFile(ExportFormat.PDF_TYPE, new File(name3), false, preset3);
~Roy
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
Participant ,
Oct 26, 2023 Oct 26, 2023

This works.  Solved thanks so much for the great help.

 

d = app.activeDocument;

if (checkForRGB()) {
alert("Document contains RGB color")
exit();

} else {
//alert("No RGB color")
}

 

~Roy
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 Beginner ,
Oct 27, 2023 Oct 27, 2023

The full workflow has InDesign set to not color manage. 

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 ,
Oct 27, 2023 Oct 27, 2023

That would cause problems with RGB objects.

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
Participant ,
Oct 27, 2023 Oct 27, 2023
LATEST

We don't use an RGB workflow.   Thanks again rob day. That bit of script was just what I needed.

~Roy
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 ,
Oct 27, 2023 Oct 27, 2023

All the CMYK images are tagged, and yes the job options are set to No Conversion.

 

If the placed CMYK images are tagged, does the InDesign document get the same CMYK assignment? Seems like you run the risk of conflicting CMYK profiles in the same document.

 

Here's the scriot as it stands.

The other way to do it is wrap your export code in a function and call it in the if statement:

 


//If checkForRGB returns false (!) there is no RGB color, so run exportPDFs() function
if (!checkForRGB()) {
    exportPDFs()
} else {
    alert("Document contains RGB color, No PDFs were exported");
}


/**
BS"D
All rights reserved (c) 2015 by Id-Extras.com
Free to use and modify but do not delete this copyright attribution.
This script will export 2 pdfs of the current document
Choose the PDF presets by altering their names below
The second PDF gets a suffix added to its name.
Modify the line below beginning name2 = to change the suffix.
For more InDesign scripts: www.Id-Extras.com
XYZ modified for 3 type pdfs...also holds all characters but removes .indd
* @ return void 
*/

function exportPDFs(){
    var d = app.activeDocument;
    var thePath;
    // Here you can choose the PDF preset
    var preset1 = app.pdfExportPresets.itemByName("HiRes_joboption");
    var preset2 = app.pdfExportPresets.itemByName("MedRes_joboption");
    var preset3 = app.pdfExportPresets.itemByName("LoRes_joboption");
    if (!(preset1.isValid)){
        alert("One of the presets does not exist. Please go to Vol1-Photoshop_Illustrator_InDesign_Acrobat_Stuff/AcrobatJobOptions_B/for actions, and load them into your setting folder");
        exit();
    }
    if (d.saved){
        thePath = String(d.fullName).replace(".indd", "") + ".pdf";
        thePath = String(new File(thePath).saveDlg());
    }else{
        thePath = String((new File).saveDlg());
    }
    thePath = thePath.replace(/\.pdf$/, "");
    var name1 = thePath+".pdf";
    // Here you can set the suffix at the end of the name
    var name2 = thePath+"_MR.pdf";
    var name3 = thePath+"_LR.pdf";
    d.exportFile(ExportFormat.PDF_TYPE, new File(name1), false, preset1);
    d.exportFile(ExportFormat.PDF_TYPE, new File(name2), false, preset2);
    d.exportFile(ExportFormat.PDF_TYPE, new File(name3), false, preset3);
}

/**
* 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);
    }
}
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
Contributor ,
Oct 26, 2023 Oct 26, 2023

I don't now if my response it's stupid....why don't you see in the links pannel if there is a rgb image?Captura de pantalla 2023-10-26 a las 17.28.12.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
Participant ,
Oct 26, 2023 Oct 26, 2023

I think Rob has the solution, but I'm going to tweak it to pass to the pdf generation without the "No RGB" alert.

~Roy
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 ,
Oct 26, 2023 Oct 26, 2023

I don't now if my response it's stupid....why don't you see in the links pannel if there is a rgb image?

 

That’s a good question, but a link could be a PDF or AI file, which could have a mix of any number of RGB, CMYK, or Lab objects. And what about native RGB colors and swatches? Why would image RGB be a problem and native or PDF RGB objects be OK?

 

Also, not sure if this helps @RoyBoySolorio , but a PDF .joboptions could have the Output Destination set DocumentCMYK—the Destination would always be the document’s assigned CMYK profile, so there would be no need for multiple .joboptions.

 

You would never want to place CMYK images and then Export to a conflicting CMYK space—that would defeat the purpose of making the CMYK conversions before placing the links.

 

Here the preset X4 DocCMYK has its Destination set to DocumentCMYK:

 

Screen Shot 2.png

 

 

The preset picks up the document’s CMYK assignment and always uses it as the Destination without modifying the .joboptions

 

Screen Shot 3.pngScreen Shot 4.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
Participant ,
Oct 26, 2023 Oct 26, 2023

Yep easy, until it's missed in the hurry of getting a proof out.  This just short circuits that potential.

~Roy
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