Change color mode

Anyone, especially newbies, asking for help with Photoshop Scripting and Photoshop Automation - as opposed to those contributing to discussion about an aspect of Photoshop Scripting

Moderators: Tom, Kukurykus

essejesse

Change color mode

Post by essejesse »

So this is giving me a headache. I can't seem to understand why this doesn't work properly.

The test file is in CMYK with a hue/saturation adjustment layer. I want to detect if the file is in CMYK, and if so, merge visible, then convert the mode. Here's my code:
Code: Select all#target Photoshop

var myDoc=app.activeDocument

if(myDoc.mode == CMYKColor){
    try {
        myDoc.mergeVisibleLayers()//try in case it's a single layer document that happens to be in CMYK
        }
    catch (err) {}
    myDoc.changeMode(ChangeMode.RGB);
    }

This does nothing. Doesn't merge layers, doesn't convert modes, just returns to ESTK with Result: undefined.

I also tried this:
Code: Select all#target Photoshop

var myDoc=app.activeDocument

if(myDoc.mode != RGBColor){
    try {
        myDoc.mergeVisibleLayers()//try in case it's a single layer document that happens to be in CMYK
        }
    catch (err) {}
    myDoc.changeMode(ChangeMode.RGB);
    }

This converts to RGB, but discards any hue/saturation layers and doesn't merge visible. I thought maybe it was because it only had one =, so I tried this:
Code: Select all#target Photoshop

var myDoc=app.activeDocument

if(myDoc.mode !== RGBColor){
    try {
        myDoc.mergeVisibleLayers()//try in case it's a single layer document that happens to be in CMYK
        }
    catch (err) {}
    myDoc.changeMode(ChangeMode.RGB);
    }

And I get the same result, it discards the hue/saturation layers and converts.

I am at a loss for why, and have to move on this afternoon, but this is holding me up on so many things.

Any help would be greatly appreciated.

Professional AI Audio Generation within Adobe Premiere Pro - Download Free Plugin here

pfaffenbichler

Change color mode

Post by pfaffenbichler »

Does this work?
Code: Select all#target Photoshop

var myDoc=app.activeDocument

if(myDoc.mode == DocumentMode.CMYK){
    try {
        myDoc.mergeVisibleLayers()//try in case it's a single layer document that happens to be in CMYK
        }
    catch (err) {}
    myDoc.changeMode(ChangeMode.RGB);
    }
essejesse

Change color mode

Post by essejesse »

Why yes, yes it does. And thank you, I appreciate it. I just couldn't look at that piece of code productively anymore. It seems like my simple mistakes are the hardest to fix.

Thanks again.
pfaffenbichler

Change color mode

Post by pfaffenbichler »

You’re welcome.

When looking for the exact spelling of some parameter it may be easier to use an alert instead of looking it up in the Object Model Viewer.
essejesse

Change color mode

Post by essejesse »

I've got to remember this in the future. The alert showed me exactly what I had missing.