# Set Background Color

**URL:** <https://forums.creativeclouddeveloper.com/t/set-background-color/3828>\
**Category:** Photoshop\
**Created:** [October 31, 2021, 7:34pm UTC](https://forums.creativeclouddeveloper.com/t/set-background-color/3828 "2021-10-31T19:34:51Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![pdophoto](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.creativeclouddeveloper.com/pdophoto/32/1304_2.png) [@pdophoto](https://forums.creativeclouddeveloper.com/u/pdophoto)\
**Post date:** [October 31, 2021, 7:34pm UTC](https://forums.creativeclouddeveloper.com/t/set-background-color/3828/1 "2021-10-31T19:34:51Z")

</div>

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?

```auto
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"
});})

```

---

<div class="post-metadata">

**Author:** ![Jarda](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.creativeclouddeveloper.com/jarda/32/1909_2.png) [@Jarda](https://forums.creativeclouddeveloper.com/u/Jarda)\
**Post date:** [October 31, 2021, 8:33pm UTC](https://forums.creativeclouddeveloper.com/t/set-background-color/3828/2 "2021-10-31T20:33:24Z")

</div>

Could you try backgroundColor with quotes?

---

<div class="post-metadata">

**Author:** ![pdophoto](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.creativeclouddeveloper.com/pdophoto/32/1304_2.png) [@pdophoto](https://forums.creativeclouddeveloper.com/u/pdophoto)\
**Post date:** [October 31, 2021, 8:57pm UTC](https://forums.creativeclouddeveloper.com/t/set-background-color/3828/3 "2021-10-31T20:57:28Z")

</div>

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.

```auto
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"
});})

}

```

---

<div class="post-metadata">

**Author:** ![Jarda](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.creativeclouddeveloper.com/jarda/32/1909_2.png) [@Jarda](https://forums.creativeclouddeveloper.com/u/Jarda)\
**Post date:** [March 6, 2023, 5:20pm UTC](https://forums.creativeclouddeveloper.com/t/set-background-color/3828/5 "2023-03-06T17:20:14Z")

</div>

Since Photoshop 24.3.0 it can be done using DOM

```auto
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();

```
