# Can You Replace A Property In batchPlay With Variable

**URL:** <https://forums.creativeclouddeveloper.com/t/can-you-replace-a-property-in-batchplay-with-variable/4692>\
**Category:** UXP Plugin API\
**Created:** [May 18, 2022, 9:53am UTC](https://forums.creativeclouddeveloper.com/t/can-you-replace-a-property-in-batchplay-with-variable/4692 "2022-05-18T09:53:12Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![IanBarber](https://avatars.discourse-cdn.com/v4/letter/i/94ad74/32.png) [@IanBarber](https://forums.creativeclouddeveloper.com/u/IanBarber)\
**Post date:** [May 18, 2022, 9:53am UTC](https://forums.creativeclouddeveloper.com/t/can-you-replace-a-property-in-batchplay-with-variable/4692/1 "2022-05-18T09:53:12Z")

</div>

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.

```auto
//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

```auto

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

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

```

---

<div class="post-metadata">

**Author:** ![Karmalakas](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.creativeclouddeveloper.com/karmalakas/32/1048_2.png) [@Karmalakas](https://forums.creativeclouddeveloper.com/u/Karmalakas)\
**Post date:** [May 18, 2022, 9:55am UTC](https://forums.creativeclouddeveloper.com/t/can-you-replace-a-property-in-batchplay-with-variable/4692/2 "2022-05-18T09:55:23Z")

</div>

I think this should work (add brackets):

```auto
[x]: {

```

---

<div class="post-metadata">

**Author:** ![IanBarber](https://avatars.discourse-cdn.com/v4/letter/i/94ad74/32.png) [@IanBarber](https://forums.creativeclouddeveloper.com/u/IanBarber)\
**Post date:** [May 18, 2022, 10:01am UTC](https://forums.creativeclouddeveloper.com/t/can-you-replace-a-property-in-batchplay-with-variable/4692/3 "2022-05-18T10:01:13Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Karmalakas](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.creativeclouddeveloper.com/karmalakas/32/1048_2.png) [@Karmalakas](https://forums.creativeclouddeveloper.com/u/Karmalakas)\
**Post date:** [May 18, 2022, 11:01am UTC](https://forums.creativeclouddeveloper.com/t/can-you-replace-a-property-in-batchplay-with-variable/4692/4 "2022-05-18T11:01:32Z")

</div>

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:

```auto
some.nested.object.key.path

```

vs

```auto
some.nested.object[key].path

```

---

<div class="post-metadata">

**Author:** ![Timothy\_Bennett](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.creativeclouddeveloper.com/timothy_bennett/32/1251_2.png) [@Timothy\_Bennett](https://forums.creativeclouddeveloper.com/u/Timothy_Bennett)\
**Post date:** [May 18, 2022, 2:05pm UTC](https://forums.creativeclouddeveloper.com/t/can-you-replace-a-property-in-batchplay-with-variable/4692/5 "2022-05-18T14:05:34Z")

</div>

Bracket notation 🤓

Simple example:

> **[Property accessors - JavaScript | MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Property_accessors)**
>
> Property accessors provide access to an object's properties by using the dot notation or the bracket notation.

Detailed article:

> **[DOT & BRACKET Notation in JavaScript](https://dev.to/capscode/dot-and-bracket-notation-in-javascript-object-12ij)**
>
> Dot notation (person.first\_name) and bracket notation (person\[first\_name\]) access object properties in JavaScript. Understanding their differences clarifies when to use each.

---

<div class="post-metadata">

**Author:** ![Karmalakas](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.creativeclouddeveloper.com/karmalakas/32/1048_2.png) [@Karmalakas](https://forums.creativeclouddeveloper.com/u/Karmalakas)\
**Post date:** [May 18, 2022, 6:48pm UTC](https://forums.creativeclouddeveloper.com/t/can-you-replace-a-property-in-batchplay-with-variable/4692/6 "2022-05-18T18:48:16Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Timothy\_Bennett](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.creativeclouddeveloper.com/timothy_bennett/32/1251_2.png) [@Timothy\_Bennett](https://forums.creativeclouddeveloper.com/u/Timothy_Bennett)\
**Post date:** [May 19, 2022, 8:19pm UTC](https://forums.creativeclouddeveloper.com/t/can-you-replace-a-property-in-batchplay-with-variable/4692/7 "2022-05-19T20:19:47Z")

</div>

Lol, I know you knew! 😜
