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

Desire Script to send Alert with the foregroundColor.model

Community Beginner ,
Jan 26, 2023 Jan 26, 2023

Copy link to clipboard

Copied

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

Views

209

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 2 Correct answers

Guide , 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.

Votes

Translate

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! 

Votes

Translate

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

Copy link to clipboard

Copied

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.

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

Copy link to clipboard

Copied

 

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.

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

Copy link to clipboard

Copied

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! 

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

Copy link to clipboard

Copied

LATEST

Thank you @Stephen_A_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!

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