How to get current White Balance value (Camera raw) and set slider value accordingly

Hi,

This is the scenario:

I have two sliders that are responsible for Temperature and Tint adjustment (within Camera raw).
I also have auto white balance button.

What I want to achieve is to automatically set sliders after clicking the “Auto White Balance” button.

I’ll have to get the values of temperature and tint after Auto WB and set the values of sliders accordingly.

Screenshot 2022-02-15 at 11.33.12

Do you have any idea how to do this?

This is what I do to set auto WB:



async function awb() {

   const layerExistsByName = (name) => {
      return Boolean(app.activeDocument?.layers?.some(layer => layer.name === name))
    }
    
    const exists = layerExistsByName("White Balance");
    
    if (exists === false) {

      await core.executeAsModal(() => {
      
            batchPlay(
                [
         {
            _obj: "make",
            _target: [
               {
                  _ref: "layer"
               }
            ],
            layerID: 3,
            _options: {
               dialogOptions: "dontDisplay"
            }
         },
         {
            _obj: "mergeVisible",
            duplicate: true,
            _options: {
               dialogOptions: "dontDisplay"
            }
         },
         {
            _obj: "set",
            _target: [
               {
                  _ref: "layer",
                  _enum: "ordinal",
                  _value: "targetEnum"
               }
            ],
            to: {
               _obj: "layer",
               name: "White Balance"
            },
            _options: {
               dialogOptions: "dontDisplay"
            }
         },
         {
            _obj: "newPlacedLayer",
            _options: {
               dialogOptions: "dontDisplay"
            }
         },
         {
            _obj: "Adobe Camera Raw Filter",
            $WBal: {
                           _enum: "$WBal",
                           _value: "auto"
            },
            _options: {
               dialogOptions: "dontDisplay"
            }
         }
      
      ], {});
      })
      }

      if (exists === true){

    

         await core.executeAsModal(() => {
      
            batchPlay(
                [
               {
                  _obj: "set",
                  _target: [
                     {
                        _ref: "filterFX",
                        _index: 1
                     },
                     {
                        _ref: "layer",
                        _enum: "ordinal",
                        _value: "targetEnum"
                     }
                  ],
                  filterFX: {
                     _obj: "filterFX",
                     filter: {
                        _obj: "Adobe Camera Raw Filter",
                        $WBal: {
                           _enum: "$WBal",
                           _value: "auto"
                        }
                     
                     }
                  },
                  _options: {
                     dialogOptions: "dontDisplay"
                  }
               }
            ], {});
         })
      }

}
   document.getElementById("btnawb").addEventListener("click", awb);

This is how the sliders are set (on example of temperature):

    
async function tempchange() {
 
   const layerExistsByName = (name) => {
     return Boolean(app.activeDocument?.layers?.some(layer => layer.name === name))
   }
   
   const exists = layerExistsByName("White Balance");
   
 let temp = document.querySelector("#tempSlider").value;

if (exists === false) {

await core.executeAsModal(() => {

      batchPlay(
          [
   {
      _obj: "make",
      _target: [
         {
            _ref: "layer"
         }
      ],
      layerID: 3,
      _options: {
         dialogOptions: "dontDisplay"
      }
   },
   {
      _obj: "mergeVisible",
      duplicate: true,
      _options: {
         dialogOptions: "dontDisplay"
      }
   },
   {
      _obj: "set",
      _target: [
         {
            _ref: "layer",
            _enum: "ordinal",
            _value: "targetEnum"
         }
      ],
      to: {
         _obj: "layer",
         name: "White Balance"
      },
      _options: {
         dialogOptions: "dontDisplay"
      }
   },
   {
      _obj: "newPlacedLayer",
      _options: {
         dialogOptions: "dontDisplay"
      }
   },
   {
      _obj: "Adobe Camera Raw Filter",
      $WBal: {
         _enum: "$WBal",
         _value: "customEnum"
      },
      $Temp: temp,
      $Tint: 0,
      _options: {
         dialogOptions: "dontDisplay"
      }
   }

], {});
})
}

if (exists === true){

    

   await core.executeAsModal(() => {

      batchPlay(
          [
         {
            _obj: "set",
            _target: [
               {
                  _ref: "filterFX",
                  _index: 1
               },
               {
                  _ref: "layer",
                  _enum: "ordinal",
                  _value: "targetEnum"
               }
            ],
            filterFX: {
               _obj: "filterFX",
               filter: {
                  _obj: "Adobe Camera Raw Filter",
                  $WBal: {
                     _enum: "$WBal",
                     _value: "customEnum"
                  },
                  $Temp: temp,
                  $Tint: 0
               }
            },
            _options: {
               dialogOptions: "dontDisplay"
            }
         }
      ], {});
   })
}


}

document.querySelector("#tempSlider").addEventListener("change", tempchange)

I really need your help :slight_smile:

If you make the layer a smartObject before applying the Camera Raw/auto white balance, then you should be able to get the $Temp & $Tint values from the SmartObject/filterFX in Batchplay.

Example below from Alchemist for the Temperate value from the Smartobject (but you would want to target your layer as I didn’t change that part)
Hope that helps.

const batchPlay = require("photoshop").action.batchPlay;

const result = await batchPlay(
[
   {
      _obj: "get",
      _target: [
         {
            _property: "smartObject"
         },
         {
            _ref: "layer",
            _id: 370
         },
         {
            _ref: "document",
            _id: 675
         }
      ],
      _options: {
         dialogOptions: "dontDisplay"
      }
   }
],{
   modalBehavior: "execute"
});
const pinned = result[0].smartObject.filterFX[0].filter.$Temp;

Hi Jason,

Thank you very much, this seems to be a good direction but I have no idea how to implement it into my code. I’ve tried everything :confused:

Im sure that I have to remove this part:

    {
            _ref: "document",
            _id: 675
         }

I’ve changed played _id to the one I use for “White Balance” layer but I don’t know what to do next.
How to place it in the code I have and how to set sliders value to be equal to “pinned”

Can I ask you for help once again? Thank you!

I tried it, and you’re right, it doesn’t work.
When opening camera raw and clicking the AUTO WB button, those Temp and Tint values are stored in the Smartfilters filter values, but doing it via batchplay only sets the Auto and does not return those other values. :frowning:
I don’t know a way around that.

Thank You Jason for help, maybe there is a way, I’m not giving up yet :blush:

Hi again Jason,

I’ve tested it again and can’t find solution yet. I’m getting “auto” as values instead of numbers :confused:

Yeah, same.
When you do the steps manually, it sets the tint & temp values…but when you do it via batch play it does not. :confused: I can’t think of a workaround.

Hi Jason,

I’m trying to get proper function that will give me the value of $Temp from camera raw applied to the layer converted to smart object but without luck. Can I kindly ask for your help? Thank you!