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

Conditional ICC Profile Test

Community Expert ,
Jun 13, 2021 Jun 13, 2021

Copy link to clipboard

Copied

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

 

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!

TOPICS
Actions and scripting

Views

1.4K

Translate

Translate

Report

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

correct answers 1 Correct answer

LEGEND , Jun 13, 2021 Jun 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.

Votes

Translate

Translate
Adobe
LEGEND ,
Jun 13, 2021 Jun 13, 2021

Copy link to clipboard

Copied

 

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

 

Votes

Translate

Translate

Report

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 13, 2021 Jun 13, 2021

Copy link to clipboard

Copied

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 { }

 

Votes

Translate

Translate

Report

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 13, 2021 Jun 13, 2021

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

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 13, 2021 Jun 13, 2021

Copy link to clipboard

Copied

Thanks, it works and that is the main thing, I just don't understand why putting it first does the trick.

 

I called it an inspector as it helps to identify what is going on, but I couldn't use it "as is" in my code. 

 

I have saved a copy of your script for future use if I need to find out what the file's colorProfileType is (NONE, WORKING, CUSTOM).

 

I can't use WORKING in this case as sRGB can't be assumed to be the working RGB, so I have to check on the name.

Votes

Translate

Translate

Report

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 13, 2021 Jun 13, 2021

Copy link to clipboard

Copied

That is not the problem to put to alert whatever you want. I just used the "type" but that is not necessary. The only what matters is the construction, that was wrong on your side. I believe in your intelligence so I assume you know the code I posted is the model to adapt to your needs.

 

The answer for me is simple. In your original code you checked if any profile was used. If that was, then a code starts closure of first condition, and ends its working. When it's not then you trigger the second condition that is equivalent of no "sRGB IEC61966-2.1" profile and no type at same time. So when it covers two cases why you expect it to check alternate condition yet?

Votes

Translate

Translate

Report

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 13, 2021 Jun 13, 2021

Copy link to clipboard

Copied

Thank you, the logic was obviously not clear to me, so thank you for explaining.

 

Perhaps I have just been banging my head against the wall for too many hours and coming back after a break would have helped.

 

Your right, by not fixing up my code and handing it to me on a silver platter and posting different looking code, you forced me to re-evaluate, but perhaps not how you expected. As your code is styled differently than I write my code, I had to ask myself why yours worked and mine didn't. It just wasn't clear to me why looking at your code.

 

I looked at my previous code and it used the same check for colorProfileType as your code did. I then decided to take it one step at a time and see if using my previous code in isolation worked. It did... So I then added the other code afterward and it all came together as I wanted.

 

I'd like to say that this was by design and that I understood your intent. 

 

I was looking for syntax and other errors, not thinking that the logic was incorrect.

Votes

Translate

Translate

Report

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
People's Champ ,
Jun 13, 2021 Jun 13, 2021

Copy link to clipboard

Copied

Always use try {} catch {}

 

... And read the documentation.

 

mnmm.png

Votes

Translate

Translate

Report

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 13, 2021 Jun 13, 2021

Copy link to clipboard

Copied

Or use conditions the proper way 😉

Votes

Translate

Translate

Report

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 13, 2021 Jun 13, 2021

Copy link to clipboard

Copied

LATEST

¯\_(ツ)_/¯

Votes

Translate

Translate

Report

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