Skip to main content
john kw62803249
Participating Frequently
January 26, 2023
Answered

Desire Script to send Alert with the foregroundColor.model

  • January 26, 2023
  • 3 replies
  • 446 views

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:

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

Thanks in advance for any help

This topic has been closed for replies.
Correct answer Stephen Marsh

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! 

3 replies

Stephen Marsh
Community Expert
Stephen MarshCommunity ExpertCorrect answer
Community Expert
January 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! 

john kw62803249
Participating Frequently
January 27, 2023

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!

Legend
January 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.

Stephen Marsh
Community Expert
Community Expert
January 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.