Copy link to clipboard
Copied
Hi, I'm wondering how to open a color dialog and write the selected color to the background color. I have this code but it writes to the foreground color, Thanks
var myColor = getColorpickerColor();
function getColorpickerColor(){
if (app.showColorPicker())
{
return app.backgroundColor;
}else{
return false;
}
};
See if this is good for you.
var myColor = getColorpickerColor();
function getColorpickerColor(){
if (app.showColorPicker())
{
return app.backgroundColor;
}else{
return false;
}
};
// Invert
var desc9 = new ActionDescriptor();
var ref2 = new ActionReference();
ref2.putProperty( charIDToTypeID( "Clr " ), charIDToTypeID( "Clrs" ));
desc9.putReference( charIDToTypeID( "null" ), ref2 );
executeAction( charIDT
...
Hi geppettol66959005 adding the “x” eXchange keyboard shortcut also affects the foreground colour... Therefore, I would suggest saving the original foreground colour and reloading it after the exchange:
var origForeCol = app.foregroundColor;
var myColor = getColorpickerColor();
function getColorpickerColor() {
if (app.showColorPicker()) {
return app.backgroundColor;
} else {
return false;
}
}
// Invert
var desc9 = new ActionDescriptor();
var ref2 = new ActionRe
...
Copy link to clipboard
Copied
See if this is good for you.
var myColor = getColorpickerColor();
function getColorpickerColor(){
if (app.showColorPicker())
{
return app.backgroundColor;
}else{
return false;
}
};
// Invert
var desc9 = new ActionDescriptor();
var ref2 = new ActionReference();
ref2.putProperty( charIDToTypeID( "Clr " ), charIDToTypeID( "Clrs" ));
desc9.putReference( charIDToTypeID( "null" ), ref2 );
executeAction( charIDToTypeID( "Exch" ), desc9, DialogModes.NO );
Copy link to clipboard
Copied
Hi geppettol66959005 adding the “x” eXchange keyboard shortcut also affects the foreground colour... Therefore, I would suggest saving the original foreground colour and reloading it after the exchange:
var origForeCol = app.foregroundColor;
var myColor = getColorpickerColor();
function getColorpickerColor() {
if (app.showColorPicker()) {
return app.backgroundColor;
} else {
return false;
}
}
// Invert
var desc9 = new ActionDescriptor();
var ref2 = new ActionReference();
ref2.putProperty(charIDToTypeID("Clr "), charIDToTypeID("Clrs"));
desc9.putReference(charIDToTypeID("null"), ref2);
executeAction(charIDToTypeID("Exch"), desc9, DialogModes.NO);
app.foregroundColor = origForeCol;
Copy link to clipboard
Copied
Thank you very much I should have thought of that 🙂
Copy link to clipboard
Copied
Thank you! thats great
Copy link to clipboard
Copied
I have also marked the answer from geppettol66959005 as correct too, this was a team effort after all!
Using the foreground/background exchange command is a practical solution, as is capturing and resetting the original foreground colour... However, surely the underlying issue is a bug and these are both just hacks to work-around the problem? Why is it that we can set the foreground but not the background via scripting in this specific manner? The DOM reference makes no special note of different behaviour or limitations etc.
Copy link to clipboard
Copied
Here is another solution ... depending on what you need.
#target photoshop
Exch();
var myColor = getColorpickerColor();
function getColorpickerColor(){
if (app.showColorPicker())
{
return app.backgroundColor;
}else{
return false;
}
};
Exch();
function Exch() {
var d=new ActionDescriptor,r=new ActionReference,TID=charIDToTypeID;r.putProperty(TID("Clr "),TID("Clrs")),d.putReference(TID("null"),r),executeAction(TID("Exch"),d,DialogModes.NO);
}