Can You Replace A Property In batchPlay With Variable

I have some batchPlay which resizes an image to 2000px but I want it to resize based on the longest side.

Rather than have 2 batchPlays can I use one but change out one of the properties with a variable.

//Resize to 2000px (can we change "height" to a variable ?
"_obj": "imageSize",
          "constrainProportions": true,
          "height": {
            "_unit": "pixelsUnit",
            "_value": 2000

tried this but it didn’t work

if (app.activeDocument.width > app.activeDocument.height){
let x = "width";

"_obj": "imageSize",
          "constrainProportions": true,
         x: {
            "_unit": "pixelsUnit",
            "_value": 2000

I think this should work (add brackets):

[x]: {

That did work @Karmalakas . What do the [ ] do ?
Thanks for solution by the way

Not sure about technical term, but it allows you to have dynamic keys in objects.
I suppose it’s more or less the same as reading a deep value from object:




Bracket notation :nerd_face:

Simple example:

Detailed article:

1 Like

Yep :slight_smile: And for a getter it’s so common, but when it comes to a setter, it’s not so obvious :slight_smile: I actually myself needed this and found not so long ago :slight_smile:

Lol, I know you knew! :stuck_out_tongue_winking_eye: