# Two little questions about layer.name and doc.bitsPerChannel

**URL:** https://forums.creativeclouddeveloper.com/t/two-little-questions-about-layer-name-and-doc-bitsperchannel/2241
**Category:** UXP Plugin API
**Created:** [November 19, 2020, 11:51am UTC](https://forums.creativeclouddeveloper.com/t/two-little-questions-about-layer-name-and-doc-bitsperchannel/2241 "2020-11-19T11:51:23Z")
**Posts on this page:** 10
**Page:** 1

<div class="post-metadata">

### Author: ![Ekrank](https://avatars.discourse-cdn.com/v4/letter/e/c89c15/32.png) [@Ekrank](https://forums.creativeclouddeveloper.com/u/Ekrank)
#### Post date: [November 19, 2020, 11:51am UTC](https://forums.creativeclouddeveloper.com/t/two-little-questions-about-layer-name-and-doc-bitsperchannel/2241/1 "2020-11-19T11:51:23Z")

</div>

Hi,  
just two little quick questions.

\_ Why :

> var doc = app.activeDocument;  
> var layer\_active = doc.activeLayer;  
> var layer\_name = layer\_active.name;

don’t work but :

> var layer\_active = doc.activeLayers[0];  
> var layer\_name = layer\_active.name;

yes ?

\_ Why :

> var doc = app.activeDocument;  
> var bits\_per\_channel = String(doc.bitsPerChannel);

don’t work ?

Thank you.

---

<div class="post-metadata">

### Author: ![simonhenke](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.creativeclouddeveloper.com/simonhenke/32/957_2.png) [@simonhenke](https://forums.creativeclouddeveloper.com/u/simonhenke)
#### Post date: [November 19, 2020, 12:35pm UTC](https://forums.creativeclouddeveloper.com/t/two-little-questions-about-layer-name-and-doc-bitsperchannel/2241/2 "2020-11-19T12:35:52Z")

</div>

I don’t see any activeLayer or bitsPerChannel properties on the [Document specification](https://www.adobe.io/photoshop/uxp/ps_reference/classes/document/), where do you take these from?

---

<div class="post-metadata">

### Author: ![Ekrank](https://avatars.discourse-cdn.com/v4/letter/e/c89c15/32.png) [@Ekrank](https://forums.creativeclouddeveloper.com/u/Ekrank)
#### Post date: [November 19, 2020, 1:09pm UTC](https://forums.creativeclouddeveloper.com/t/two-little-questions-about-layer-name-and-doc-bitsperchannel/2241/3 "2020-11-19T13:09:28Z")

</div>

From the old spec. I just want to convert my old script to the new specs.  
For activeLayer, i can understand activeLayer = activeLayers[0].  
But for bits per channel, i dont found something equal.  
I have a function with something like that.

> **[Bits per channel photoshop scripts](https://community.adobe.com/t5/photoshop/bits-per-channel-photoshop-scripts/td-p/10667048?page=1)**
>
> Hello, please tell me how to indicate in the script the conditions "if the document is 8 bits then .... if 16 bits then ...". Thank you.

---

<div class="post-metadata">

### Author: ![simonhenke](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.creativeclouddeveloper.com/simonhenke/32/957_2.png) [@simonhenke](https://forums.creativeclouddeveloper.com/u/simonhenke)
#### Post date: [November 19, 2020, 2:11pm UTC](https://forums.creativeclouddeveloper.com/t/two-little-questions-about-layer-name-and-doc-bitsperchannel/2241/4 "2020-11-19T14:11:25Z")

</div>

You cannot reuse the old code, with PS 2021 / UXP they introduced a completely new API, at least for the DOM. They’re still working on it, so many features are missing yet. You can achieve almost everything with batchPlay though, which is the “new generation” of ActionManager code.

You could get the channel bits via

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

const deph = await batchPlay(
[
   {
      "_obj": "get",
      "_target": [
         {
            "_property": "depth"
         },
         {
            "_ref": "document",
            "_enum": "ordinal", 
            "_value": "targetEnum"
         }
      ],
   }
],{
   "synchronousExecution": true,
   "modalBehavior": "fail"
})[0].depth
```

---

<div class="post-metadata">

### Author: ![Ekrank](https://avatars.discourse-cdn.com/v4/letter/e/c89c15/32.png) [@Ekrank](https://forums.creativeclouddeveloper.com/u/Ekrank)
#### Post date: [November 19, 2020, 2:42pm UTC](https://forums.creativeclouddeveloper.com/t/two-little-questions-about-layer-name-and-doc-bitsperchannel/2241/5 "2020-11-19T14:42:26Z")

</div>

Thank you for the quick answer.  
Ok. I understand it’s the beginning and the will add a lot of features in the future.  
So, maybe i must wait to convert my plugin.  
Thanks again for the answer.

---

<div class="post-metadata">

### Author: ![Ekrank](https://avatars.discourse-cdn.com/v4/letter/e/c89c15/32.png) [@Ekrank](https://forums.creativeclouddeveloper.com/u/Ekrank)
#### Post date: [November 23, 2020, 9:12am UTC](https://forums.creativeclouddeveloper.com/t/two-little-questions-about-layer-name-and-doc-bitsperchannel/2241/6 "2020-11-23T09:12:13Z")

</div>

Nope.  
I cant see my mistake.  
Why your example with “mode” (find on an other topic) works fine and why my example with “depth” doesnt.

**Depth :**

const batchPlay = require(“photoshop”).action.batchPlay;

```
const result = await batchPlay(
[
   {
      "_obj": "get",
      "_target": [
         {
            "_property": "mode"
         },
         {
            "_ref": "document"
         }
      ],
      "_options": {
         "dialogOptions": "dontDisplay"
      }
   }
],{
   "synchronousExecution": false,
   "modalBehavior": "fail"
});

var bits_per_channel_t = result[0].depth;

```

showAlert(bits\_per\_channel\_t.toString());

.

**Mode :**  
const batchPlay = require(“photoshop”).action.batchPlay;

```
const result = await batchPlay(
[
   {
      "_obj": "get",
      "_target": [
         {
            "_property": "mode"
         },
         {
            "_ref": "document",
            "_enum": "ordinal",
            "_value": "targetEnum"
         }
      ],
      "_options": {
         "dialogOptions": "dontDisplay"
      }
   }
],{
   "synchronousExecution": false,
   "modalBehavior": "fail"
});

var bits_per_channel_t = result[0].mode._value;

showAlert(bits_per_channel_t.toString());
```

---

<div class="post-metadata">

### Author: ![simonhenke](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.creativeclouddeveloper.com/simonhenke/32/957_2.png) [@simonhenke](https://forums.creativeclouddeveloper.com/u/simonhenke)
#### Post date: [November 23, 2020, 12:44pm UTC](https://forums.creativeclouddeveloper.com/t/two-little-questions-about-layer-name-and-doc-bitsperchannel/2241/7 "2020-11-23T12:44:39Z")

</div>

You’re fetching the mode property from the active Document, but then try to extract the depth property from the resulting descriptor - which is undefined of course. That’s the mistake.

Check out the example I posted above

---

<div class="post-metadata">

### Author: ![Pierre\_G](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.creativeclouddeveloper.com/pierre_g/32/971_2.png) [@Pierre\_G](https://forums.creativeclouddeveloper.com/u/Pierre_G)
#### Post date: [November 23, 2020, 12:51pm UTC](https://forums.creativeclouddeveloper.com/t/two-little-questions-about-layer-name-and-doc-bitsperchannel/2241/8 "2020-11-23T12:51:13Z")

</div>

> [@Ekrank](#):
>
> ```auto
> const result = await batchPlay(
> 
> ```

Hi, this is the code I’m using:

```
async function myDepth() {
  const result = await batchPlay(
    [{
      "_obj": "get",
      "_target": [{
          "_property": "depth"
        },
        {
          "_ref": "document",
          "_enum": "ordinal",
          "_value": "targetEnum"
        }
      ],
      "_options": {
        "dialogOptions": "dontDisplay"
      }
    }], {
      "synchronousExecution": false,
      "modalBehavior": "fail"
    });

  var documentDepth = result[0].depth;
  app.showAlert(`The Document is in ${documentDepth.toString()} bits`);
}

async function myMode() {
  const result = await batchPlay(

    [{
      "_obj": "get",
      "_target": [{
          "_property": "mode"
        },
        {
          "_ref": "document",
          "_enum": "ordinal",
          "_value": "targetEnum"
        }
      ],
      "_options": {
        "dialogOptions": "dontDisplay"
      }
    }], {
      "synchronousExecution": false,
      "modalBehavior": "fail"
    });

  var documentMode = result[0].mode._value;
  app.showAlert(`The Document is in ${documentMode.toString()} mode`);
}

```

---

<div class="post-metadata">

### Author: ![simonhenke](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.creativeclouddeveloper.com/simonhenke/32/957_2.png) [@simonhenke](https://forums.creativeclouddeveloper.com/u/simonhenke)
#### Post date: [November 23, 2020, 1:36pm UTC](https://forums.creativeclouddeveloper.com/t/two-little-questions-about-layer-name-and-doc-bitsperchannel/2241/9 "2020-11-23T13:36:40Z")

</div>

> [@Pierre\_G](#):
>
> `myDepth()`

> [@Pierre\_G](#):
>
> `myMode()`

Pretty possessive to steal those from the document, isn’t it? Just kidding 😄

---

<div class="post-metadata">

### Author: ![Ekrank](https://avatars.discourse-cdn.com/v4/letter/e/c89c15/32.png) [@Ekrank](https://forums.creativeclouddeveloper.com/u/Ekrank)
#### Post date: [November 23, 2020, 4:37pm UTC](https://forums.creativeclouddeveloper.com/t/two-little-questions-about-layer-name-and-doc-bitsperchannel/2241/10 "2020-11-23T16:37:23Z")

</div>

Ok, it works now.  
Thanks again. 🙂
