# bringToFront (working with Folders)

**URL:** <https://forums.creativeclouddeveloper.com/t/bringtofront-working-with-folders/4151>\
**Category:** UXP Plugin API\
**Created:** [January 15, 2022, 8:54pm UTC](https://forums.creativeclouddeveloper.com/t/bringtofront-working-with-folders/4151 "2022-01-15T20:54:24Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![RyanBlack](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.creativeclouddeveloper.com/ryanblack/32/1911_2.png) [@RyanBlack](https://forums.creativeclouddeveloper.com/u/RyanBlack)\
**Post date:** [January 15, 2022, 8:54pm UTC](https://forums.creativeclouddeveloper.com/t/bringtofront-working-with-folders/4151/1 "2022-01-15T20:54:24Z")

</div>

Any solutions to this, I’ve tied using the

`layer.bringToFront();`

> **[Photoshop API—UXP for Adobe Photoshop](https://developer.adobe.com/photoshop/uxp/2022/ps_reference/)**
>
> Learn about the Photoshop API that is exposed through UXP for developers of plugins and scripts.

The info is void on:

> **[Layer](https://developer.adobe.com/photoshop/uxp/2022/ps_reference/classes/layer/)**

Also, tried using batchPlay and it isn’t working using what Alchemist provides.

---

<div class="post-metadata">

**Author:** ![matakus](https://avatars.discourse-cdn.com/v4/letter/m/49beb7/32.png) [@matakus](https://forums.creativeclouddeveloper.com/u/matakus)\
**Post date:** [January 15, 2022, 11:25pm UTC](https://forums.creativeclouddeveloper.com/t/bringtofront-working-with-folders/4151/2 "2022-01-15T23:25:07Z")

</div>

this should work in batch play, you’d have to wrap the function in executeAsModal for API 2

```auto
const result = await batchPlay(
[
   {
      _obj: "move",
      _target: [
         {
            _ref: "layer",
            _enum: "ordinal",
            _value: "targetEnum"
         }
      ],
      to: {
         _ref: "layer",
         _enum: "ordinal",
         _value: "front"
      },
   }
],{
   synchronousExecution: false,
});

```

---

<div class="post-metadata">

**Author:** ![RyanBlack](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.creativeclouddeveloper.com/ryanblack/32/1911_2.png) [@RyanBlack](https://forums.creativeclouddeveloper.com/u/RyanBlack)\
**Post date:** [January 15, 2022, 11:55pm UTC](https://forums.creativeclouddeveloper.com/t/bringtofront-working-with-folders/4151/3 "2022-01-15T23:55:48Z")

</div>

For some reason I can not get this to work with folders! It selects the two folders and halts, I also don’t get any issues in the debug

```auto
{
         "_obj": "select",
         "_target": [
            {
               "_ref": "layer",
               "_name": "Color"
            }
         ],
         "makeVisible": false,
         "layerID": [
            434
         ],
         "_isCommand": false
      },
      {
         "_obj": "select",
         "_target": [
            {
               "_ref": "layer",
               "_name": "Color"
            }
         ],
         "makeVisible": false,
         "layerID": [
            434
         ],
         "_isCommand": true
      },
      {
         "_obj": "select",
         "_target": [
            {
               "_ref": "layer",
               "_name": "Ambient"
            }
         ],
         "selectionModifier": {
            "_enum": "selectionModifierType",
            "_value": "addToSelectionContinuous"
         },
         "makeVisible": false,
         "layerID": [
            431,
            434
         ],
         "_isCommand": false
      },
      {
         "_obj": "select",
         "_target": [
            {
               "_ref": "layer",
               "_name": "Ambient"
            }
         ],
         "selectionModifier": {
            "_enum": "selectionModifierType",
            "_value": "addToSelectionContinuous"
         },
         "makeVisible": false,
         "layerID": [
            431,
            434
         ],
         "_isCommand": true
      },

      {
         "_obj": "move",
         "_target": [
            {
               "_ref": "layer",
               "_enum": "ordinal",
               "_value": "targetEnum"
            }
         ],
         "to": {
            "_ref": "layer",
            "_enum": "ordinal",
            "_value": "front"
         },
      },

   ], { synchronousExecution: false, })

}

```

---

<div class="post-metadata">

**Author:** ![RyanBlack](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.creativeclouddeveloper.com/ryanblack/32/1911_2.png) [@RyanBlack](https://forums.creativeclouddeveloper.com/u/RyanBlack)\
**Post date:** [January 16, 2022, 12:08am UTC](https://forums.creativeclouddeveloper.com/t/bringtofront-working-with-folders/4151/4 "2022-01-16T00:08:54Z")

</div>

Ok, when I hit the button twice, the second time it will place the folder on top. What does that mean?

---

<div class="post-metadata">

**Author:** ![matakus](https://avatars.discourse-cdn.com/v4/letter/m/49beb7/32.png) [@matakus](https://forums.creativeclouddeveloper.com/u/matakus)\
**Post date:** [January 16, 2022, 12:49am UTC](https://forums.creativeclouddeveloper.com/t/bringtofront-working-with-folders/4151/5 "2022-01-16T00:49:01Z")

</div>

This will select the layers called “Color” and “Ambient”, then move them to the top. If you change the select object to the folder name, it’ll select the folder.

> const result = await batchPlay(  
> [  
> {  
> \_obj: “select”,  
> \_target: [  
> {  
> \_ref: “layer”,  
> \_name: “Color”  
> }  
> ],  
> },  
> {  
> \_obj: “select”,  
> \_target: [  
> {  
> \_ref: “layer”,  
> \_name: “Ambient”  
> }  
> ],  
> selectionModifier: {  
> \_enum: “selectionModifierType”,  
> \_value: “addToSelection”  
> },  
> },  
> {  
> \_obj: “move”,  
> \_target: [  
> {  
> \_ref: “layer”,  
> \_enum: “ordinal”,  
> \_value: “targetEnum”  
> }  
> ],  
> to: {  
> \_ref: “layer”,  
> \_enum: “ordinal”,  
> \_value: “front”  
> },  
> }  
> ],{  
> synchronousExecution: false,  
> });

---

<div class="post-metadata">

**Author:** ![RyanBlack](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.creativeclouddeveloper.com/ryanblack/32/1911_2.png) [@RyanBlack](https://forums.creativeclouddeveloper.com/u/RyanBlack)\
**Post date:** [January 16, 2022, 1:22am UTC](https://forums.creativeclouddeveloper.com/t/bringtofront-working-with-folders/4151/6 "2022-01-16T01:22:04Z")

</div>

Those are the folder names /shrug. There aren’t any layers with those names.

---

<div class="post-metadata">

**Author:** ![RyanBlack](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.creativeclouddeveloper.com/ryanblack/32/1911_2.png) [@RyanBlack](https://forums.creativeclouddeveloper.com/u/RyanBlack)\
**Post date:** [January 16, 2022, 3:36pm UTC](https://forums.creativeclouddeveloper.com/t/bringtofront-working-with-folders/4151/7 "2022-01-16T15:36:46Z")

</div>

Is this what you’re referring to? The name is the folder and not a layer. It selects the folders and then pauses.

```auto
{
_obj: “select”,
_target: [
{
_ref: “layer”,
_name: “FOLDER NAME”
}

```

---

<div class="post-metadata">

**Author:** ![matakus](https://avatars.discourse-cdn.com/v4/letter/m/49beb7/32.png) [@matakus](https://forums.creativeclouddeveloper.com/u/matakus)\
**Post date:** [January 18, 2022, 1:30am UTC](https://forums.creativeclouddeveloper.com/t/bringtofront-working-with-folders/4151/8 "2022-01-18T01:30:42Z")

</div>

As far as I can tell, photoshop treats the selection of folders as layers.

If you have a folder called “Group01”, then change the selection name to “Group01”

> {  
> \_ref: “layer”,  
> \_name: “Group01”  
> }

---

<div class="post-metadata">

**Author:** ![RyanBlack](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.creativeclouddeveloper.com/ryanblack/32/1911_2.png) [@RyanBlack](https://forums.creativeclouddeveloper.com/u/RyanBlack)\
**Post date:** [January 19, 2022, 3:56pm UTC](https://forums.creativeclouddeveloper.com/t/bringtofront-working-with-folders/4151/9 "2022-01-19T15:56:11Z")

</div>

I don’t have an issue selecting, as the folders highlight and then nothing happens.

If I run the code once more, then one of the folders move to the top.

---

<div class="post-metadata">

**Author:** ![matakus](https://avatars.discourse-cdn.com/v4/letter/m/49beb7/32.png) [@matakus](https://forums.creativeclouddeveloper.com/u/matakus)\
**Post date:** [January 20, 2022, 12:32am UTC](https://forums.creativeclouddeveloper.com/t/bringtofront-working-with-folders/4151/10 "2022-01-20T00:32:31Z")

</div>

If you record the steps in alchemist yourself, does the folder move as expected if you just play the steps back?

The above code works as expected for me on multiple plugins, OS etc

---

<div class="post-metadata">

**Author:** ![matakus](https://avatars.discourse-cdn.com/v4/letter/m/49beb7/32.png) [@matakus](https://forums.creativeclouddeveloper.com/u/matakus)\
**Post date:** [January 20, 2022, 10:44am UTC](https://forums.creativeclouddeveloper.com/t/bringtofront-working-with-folders/4151/11 "2022-01-20T10:44:09Z")

</div>

Read this, could be an issue with the OS

> [@\[bug\] Sometimes adding multiple descriptors to a batchPlay doesn't work correctly](http://forums.creativeclouddeveloper.com/t/bug-sometimes-adding-multiple-descriptors-to-a-batchplay-doesnt-work-correctly/2326):
>
> I’ve had a few occurrences where using batch play with multiple descriptors in the same batch play doesn’t work as it should. Splitting it up into multiple batchPlay descriptors fixes the issue. One time, it worked correctly on my PC and not Mac but can’t remember which exact descriptor that was. Here is one example that I just ran into. In this case, it is a pretty specific situation that doesn’t work correctly. I have a 1 layer file that is NOT a background layer. I’m adding a new layer …

---

<div class="post-metadata">

**Author:** ![RyanBlack](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.creativeclouddeveloper.com/ryanblack/32/1911_2.png) [@RyanBlack](https://forums.creativeclouddeveloper.com/u/RyanBlack)\
**Post date:** [January 21, 2022, 11:52pm UTC](https://forums.creativeclouddeveloper.com/t/bringtofront-working-with-folders/4151/12 "2022-01-21T23:52:08Z")

</div>

Thanks man, I think there is a bug and will have to break it up, I ended up making a work around, but still want to get this to work… That said, I got sidetracked in another area of the plugin, I’ll circle back and update you!
