Skip to main content
Stephen Marsh
Community Expert
Community Expert
June 13, 2021
Answered

Conditional ICC Profile Test

  • June 13, 2021
  • 1 reply
  • 1905 views

I have been spinning my wheels trying to get the following code to work:

 

var doc = app.activeDocument;

if (doc.colorProfileName === "sRGB IEC61966-2.1") {
    alert("sRGB = True");
    // Do something #1

} else if (doc.colorProfileName !== "sRGB IEC61966-2.1") {
    alert("sRGB = False");
    // Do something #2

} else {}

alert("Untagged");
// Do something #3

 

 

The closest that I have come to for answers are the following topics:

 

https://community.adobe.com/t5/photoshop/how-to-turn-off-color-management-for-a-document-from-a-script/m-p/2798744

 

https://community.adobe.com/t5/photoshop/color-profile-conditions/m-p/7734629

 

https://simulatedesign.com/scripting-color-management-in-photoshop/

 

That being said, I just can't get the test/check for a doc with no colour management or no ICC profile to fire the alert.

 

I have tried using four conditionals, with the untagged check being an else if and then adding a blank else at the end, however, the syntax is killing me when it comes to checking for the untagged/don't colour manage this document condition.

 

 

var doc = app.activeDocument;

if (doc.colorProfileName === "sRGB IEC61966-2.1") {
    alert("sRGB = True");
    // Do something #1

} else if (doc.colorProfileName !== "sRGB IEC61966-2.1") {
    alert("sRGB = False");
    // Do something #2

} else if (doc.colorProfileType === ColorProfile.NONE) {
    alert("Untagged");
    // Do something #3
} else {}

 

 

I'm guessing that I am missing something simple, hoping somebody can help, thanks!

This topic has been closed for replies.
Correct answer Kukurykus

Your edited code is the same I posted. That was my intention to revert the order. btw I don't know what you mean by 'inspector' but your previous code called out second condition, so not untagged that is third. Mine calls out only last condition for the NONE, first in my case.

1 reply

Kukurykus
Legend
June 13, 2021

 

if (unescape(cPT = (aD = activeDocument).colorProfileType).indexOf('NONE') + 1) alert(cPT)
else if(aD.colorProfileName == 'sRGB IEC61966-2.1') alert(cPT) else alert(cPT)

 

Stephen Marsh
Community Expert
Community Expert
June 13, 2021

Thank you @Kukurykus –

 

Your code provides a nice "inspector"...

 

For the untagged test, your code returns the same as my previous tests, i.e. ColorProfile.NONE

 

If I only use a single condition check, this works fine:

 

 

var doc = app.activeDocument;
if (doc.colorProfileType === ColorProfile.NONE) {
    alert("Untagged");
    // Do something #3
}

 

 

However, when I include it in the "full" test script, it fails to return the alert:

 

 

var doc = app.activeDocument;

if (doc.colorProfileName === "sRGB IEC61966-2.1") {
    alert("sRGB = True");
    // Do something #1

} else if (doc.colorProfileName !== "sRGB IEC61966-2.1") {
    alert("sRGB = False");
    // Do something #2

} else if (doc.colorProfileType === ColorProfile.NONE) {
    alert("Untagged");
    // Do something #3
} else { }

 

 

EDIT: It appears to work when I swap the order around!?

 

var doc = app.activeDocument;

if (doc.colorProfileType === ColorProfile.NONE) {
    alert("Untagged");
    // Do something #1

} else if (doc.colorProfileName !== "sRGB IEC61966-2.1") {
    alert("sRGB = False");
    // Do something #2

} else if (doc.colorProfileName === "sRGB IEC61966-2.1") {
    alert("sRGB = True");
    // Do something #3
} else { }

 

Kukurykus
KukurykusCorrect answer
Legend
June 13, 2021

Your edited code is the same I posted. That was my intention to revert the order. btw I don't know what you mean by 'inspector' but your previous code called out second condition, so not untagged that is third. Mine calls out only last condition for the NONE, first in my case.