Skip to main content
Inspiring
June 23, 2011
Question

RGB/CMYK to Grayscale by script or right click?

  • June 23, 2011
  • 3 replies
  • 11143 views

Is there a way to convert RGB/CMYK to Grayscale by script?

I need to convert 475 images to grayscale. But I can´t use Color2Gray plugin into Indesign for erros message - I don´t know why.

I know there is another method in Indesign to make it (menu Effect...) but cause troubles in out.

Maybe there is a script like right click into Windows Explorer but I don't know anyone.

This topic has been closed for replies.

3 replies

Participant
March 26, 2012

A bit of thread necromancy here, sorry!

Is there a way to get the script to save the files with different names in the same directory and then update the indesign file with the new links?

Thanks!

John Hawkinson
Inspiring
March 26, 2012

It's certainly doable.

On the Photoshop side, you can change

psDoc.close(SaveOptions.SAVECHANGES);

to

psDoc.saveAs(new File(newPath));

psDoc.close(SaveOptions.DONOTSAVECHANGES);

and then you just need to generate newPath as your alternate filename. (Doing so proably involves breaking up link.filePath into the file and the directory in order for it to play nice.) Probably it would be best for newPath to be an argument you pass to Photoshop so you would only calculate it once. Then you would have InDesign call link.relink(newPath);.

Participant
March 29, 2012

Hmmm that sounds like it'd work, from my limited scripting knowledge... now to try to kludge it together without blowing up my computer!

Kasyan Servetsky
Legend
June 26, 2011

Here is my first attempt :

#target indesign

var doc = app.activeDocument,
links = doc.links,
i, link, image;

UpdateAllOutdatedLinks();

for (i = links.length-1; i >= 0; i--) {
     link = links;
     if (link.status == LinkStatus.NORMAL) {
          image = link.parent;
          if (image.space == "RGB" || image.space == "CMYK") {
               CreateBridgeTalkMessage(link.filePath);
          }
     }
}

UpdateAllOutdatedLinks();

//===================== FUNCTIONS ===============================
function CreateBridgeTalkMessage(imagePath) {
     var bt = new BridgeTalk();
     bt.target = "photoshop";
     bt.body = ResaveInPS.toSource()+"("+imagePath.toSource()+");";
     bt.onError = function(errObj) {
          $.writeln("Error: " + errObj.body);
     }
     bt.onResult = function(resObj) {}
     bt.send(30);
}

function ResaveInPS(imagePath) {
     var psDoc;
     app.displayDialogs = DialogModes.NO;
     psDoc = app.open(new File(imagePath));
     psDoc.changeMode(ChangeMode.GRAYSCALE);
     psDoc.close(SaveOptions.SAVECHANGES);
     app.displayDialogs = DialogModes.ALL;
}

function UpdateAllOutdatedLinks() {
     var link, c;
     for (var c = doc.links.length-1; c >= 0; c--) {
          link = doc.links;
          if (link.status == LinkStatus.LINK_OUT_OF_DATE) link.update();
     }
}

Written in CS3, Windows.

John Hawkinson
Inspiring
June 27, 2011

Note that this script permanently and irreversibly overwrites the original CMYK or RGB image with a grayscale version, losing possibly irreplacable information. So be careful!

John Hawkinson
Inspiring
June 23, 2011

This is a bit tricky.

To do it properly you need to use Photoshop.

Are they all in the same folder? You could use a batch action in Photoshop to convert them all, keeping the filenames the same (perhaps convert Folder1 to Folder2 and then rename the folders). Then update all links in InDesign.