Skip to main content
Inspiring
June 23, 2011
Question

RGB/CMYK to Grayscale by script or right click?

  • June 23, 2011
  • 3 replies
  • 11119 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.

Cris IderAuthor
Inspiring
July 23, 2011

Sorry for I´m too late.

But this script it´s not working to me.

I tested in Indesign CS5 (Windows 7) / Photoshop CS5 and Photoshop 7.0

Nothing happened. Just Javascript console open with this message: Error: ERROR: TARGET COULD NOT BE LAUNCHED.

Thanks anyway.

Cris IderAuthor
Inspiring
July 23, 2011

Chris, how are you trying to use the script?

Did you install it in your InDesign scripts folder?

See How to Install InDesign/InCopy Scripts.

Are you running it from InDesign?

If you're running it from the ESTK, do you have InDesign selected as a target? Is the link icon green? [sometimes, yes, even when the script specifies #target indesign, it can get confused.]


I use the script correctly.

Open Indesign, New Document, Place a color (RGB) picture (jpg or tif), open Script Panel, find the script "Color to Gray" (in my adobe script folder), and apply it on seleceted picture.

So the java script editor open, and nothings happen (just the message: "error: error target can not lanched" on java scritp console panel.)

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.