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

RGB/CMYK to Grayscale by script or right click?

Explorer ,
Jun 23, 2011 Jun 23, 2011

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.

TOPICS
Scripting
11.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
LEGEND ,
Jun 23, 2011 Jun 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.

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
Valorous Hero ,
Jun 26, 2011 Jun 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.

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 ,
Jun 26, 2011 Jun 26, 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!

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
Explorer ,
Jun 27, 2011 Jun 27, 2011

Thanks, but nothing's happened. My system is Windows 7, Indesign CS5.

Maybe my photoshop is corrupted or just works in Indesign CS3.

I will try another pc.

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 ,
Jun 27, 2011 Jun 27, 2011

@Cris,
just tested Kasyans script. It works fine in InDesign CS5 (7.0.4) together with PhotoShop CS5 Extended (12.0.2) under Mac OS X 10.5.8.
It's not very fast, so if you test against an InDesign document with a lot of images, be patient.

Comment on using an automated process to convert to "grayscale":

you will get better results if you do the conversion image by image individually in PhotoShop. First use "Image/Corrections/BlackAndWhite" (I use a german PhotoShop, so this might not be the correct menu names) in RGB mode to prepare the image, then convert to grayscale mode.

Uwe

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
Valorous Hero ,
Jun 27, 2011 Jun 27, 2011

... use "Image/Corrections/BlackAndWhite" (I use a german PhotoShop, so this might not be the correct menu names)...

Image > Adjustments > Black & White...

Thanks for confirming that it works in CS5, Uwe.

Regards,

Kas

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
Valorous Hero ,
Jun 27, 2011 Jun 27, 2011

Unfortunately I can't test it in CS5 until I get to my work on Wednesday. I made a quick test in CS3 on my home computer and it worked for me.

Regards,

Kas

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
Explorer ,
Jul 23, 2011 Jul 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.

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 ,
Jul 23, 2011 Jul 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.]

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
Explorer ,
Jul 23, 2011 Jul 23, 2011

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

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 ,
Jul 23, 2011 Jul 23, 2011

Oh, I see. It's almost certainly this part, where it calls to Photoshop:

     var bt = new BridgeTalk();
     bt.target = "photoshop";
     bt.body = ResaveInPS.toSource()+"("+imagePath.toSource()+");";
     bt.onError = function(errObj) {
          $.writeln("Error: " + errObj.body);

Not sure why it's not working for you. Something weird about your photoshop installation, I guess.

I would try targetting photoshop with some trivial scripts from the ESTK, but that's not easy if you're not familiar with it.

Perhaps someone else will have an idea. Good luck.

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 28, 2011 Oct 28, 2011

@John!
I found a way to run the script into an error.

just add a comment to the function "ResaveInPS" like that:

function ResaveInPS(imagePath) {

    var psDoc;

    app.displayDialogs = DialogModes.NO;

    psDoc = app.open(new File(imagePath));

    psDoc.changeMode(ChangeMode.GRAYSCALE);

    psDoc.close(SaveOptions.SAVECHANGES);

    //Comment here

    app.displayDialogs = DialogModes.ALL;

}

I'm not exactly sure why is that, but I think it has to do with the .toSource() command in line 25.

Uwe

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 ,
Oct 28, 2011 Oct 28, 2011

Good catch, Uwe.

It appears that, at least on the Mac, .toSource() replaces newlines with spaces. And since //-style comments depend on a newline to terminate them, the comment is never terminated, so the function's close-brace } is never found.

An easy demonstration:

testf = function () {

   a=1;

   //comment

}

testfs = testf.toSource();

testfse = eval(testfs);

testfsef = testfse.toSource();

$.writeln("no wrapper:",testfs);

$.writeln("w/ wrapper:", testfsef);

The easy workaround is to use a /* comment */ instead of a //comment.

I'll file a bug though.

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
Valorous Hero ,
Jul 24, 2011 Jul 24, 2011

I just tested it in CS5  —  InDesign 7.0.4, Photoshop 12.0.4, Windows 7 — it works for me as expected.

Kas

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
New Here ,
Mar 26, 2012 Mar 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!

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 ,
Mar 26, 2012 Mar 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);.

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
New Here ,
Mar 29, 2012 Mar 29, 2012
LATEST

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

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