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

Desire Script to send Alert with the foregroundColor.model

Community Beginner ,
Jan 26, 2023 Jan 26, 2023

I have just a little experience with PS scripts so struggling to make a script what will read the foreground color model that is being used.  Possible color models that are allowed are

RGB

CMYK

GRAYSCALE

LAB

HSB

NONE

As shown in SolidColor:

Screen Shot 2023-01-26 at 2.15.04 PM.jpg

Having the result show in an Alert would be all I would need.

Thanks in advance for any help

TOPICS
Actions and scripting
433
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

correct answers 2 Correct answers

Mentor , Jan 26, 2023 Jan 26, 2023

 

s2t = stringIDToTypeID;
(r = new ActionReference()).putProperty(s2t('property'), p = s2t('foregroundColor'));
r.putEnumerated(s2t('application'), s2t('ordinal'), s2t('targetEnum'));
alert(typeIDToStringID(executeActionGet(r).getObjectType(p)));

 

* Photoshop updates foregroundColor object only after changing the color. If you switched the color selection mode, but did not change the color itself, the color model will not change.

Translate
Community Expert , Jan 26, 2023 Jan 26, 2023

Well, that was easier than I thought!

 

alert(app.foregroundColor.model.toString().replace(/^.+\./, ""));

 

@jazz-y – thank you for the tip about the model not updating unless a value is changed, that unknown info would have driven me crazy! 

Translate
Adobe
Community Expert ,
Jan 26, 2023 Jan 26, 2023

For the foreground colour swatch, I think that you will need to look into the solid fill colour options. Sorry I'm not in front of a computer to check or write the code at this moment.

 

Edit: Setting values is easier than getting values, so you may need AM code rather than regular DOM code.

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
Mentor ,
Jan 26, 2023 Jan 26, 2023

 

s2t = stringIDToTypeID;
(r = new ActionReference()).putProperty(s2t('property'), p = s2t('foregroundColor'));
r.putEnumerated(s2t('application'), s2t('ordinal'), s2t('targetEnum'));
alert(typeIDToStringID(executeActionGet(r).getObjectType(p)));

 

* Photoshop updates foregroundColor object only after changing the color. If you switched the color selection mode, but did not change the color itself, the color model will not change.

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 ,
Jan 26, 2023 Jan 26, 2023

Well, that was easier than I thought!

 

alert(app.foregroundColor.model.toString().replace(/^.+\./, ""));

 

@jazz-y – thank you for the tip about the model not updating unless a value is changed, that unknown info would have driven me crazy! 

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 Beginner ,
Jan 26, 2023 Jan 26, 2023
LATEST

Thank you @Stephen Marsh Stephen, that works perfect!

Also thanks to @jazz-y as you identified a corner case that could make things very confusing.

Much appreciation to you both!

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