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:
Having the result show in an Alert would be all I would need.
Thanks in advance for any help
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.
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!
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.
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.
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!
Copy link to clipboard
Copied
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!