Set Background Color

Hi,
I think this could be a bug.
I am using PS 23.0.0.
The following script should set the background color but it sets the foreground color.
I maybe wrong so, can someone check and give feedback please?

var exeModal = require('photoshop').core.executeAsModal;

await exeModal(() => {
const result1 =  batchPlay(
[
   {
      "_obj": "set",
      "_target": [
         {
            "_ref": "color",
            "_property": backgroundColor
         }
      ],
      "to": {
         "_obj": "HSBColorClass",
         "hue": {
            "_unit": "angleUnit",
            "_value": 222
         },
         "saturation": 48,
         "brightness": 59
      },
      "source": "photoshopPicker",
      "_isCommand": true,
      "_options": {
         "dialogOptions": "dontDisplay"
      }
   }
],{
   "synchronousExecution": true,
   "modalBehavior": "execute"
});})

Could you try backgroundColor with quotes?

Sorry, my mistake (as usual) but it does not work.
To get back to the main question, maybe the error is in my script but, it works very well to set foreground color.
I call the function with an argument: groundColor (“backgroundColor”); which sets the foreground color.
To set forground I use groundColor (“foregroundColor”); which sets the foreground color.

const groundColor =  async (ground) => {
var newColor = ColorPicker();
var Hue = newColor.color.hue._value;
var Sat = newColor.color.saturation;
var Bright = newColor.color.brightness;

await exeModal(() => {
const result1 =  batchPlay(
[
   {
      "_obj": "set",
      "_target": [
         {
            "_ref": "color",
            "_property": ground
         }
      ],
      "to": {
         "_obj": "HSBColorClass",
         "hue": {
            "_unit": "angleUnit",
            "_value": Hue
         },
         "saturation": Sat,
         "brightness": Bright
      },
      "source": "photoshopPicker",
      "_isCommand": true,
      "_options": {
         "dialogOptions": "dontDisplay"
      }
   }
],{
   "synchronousExecution": true,
   "modalBehavior": "execute"
});})

}
1 Like

Since Photoshop 24.3.0 it can be done using DOM

const {executeAsModal} = require("photoshop").core;
const {batchPlay} = require("photoshop").action;

async function actionCommands() {
    const newColor = new app.SolidColor();
    newColor.rgb.hexValue="#ff00ff";
    app.backgroundColor = newColor;
}

async function runModalFunction() {
   await executeAsModal(actionCommands, {"commandName": "Action Commands"});
}

await runModalFunction();
1 Like