# Workaround for missing API methods (get all layercomps)

**URL:** <https://forums.creativeclouddeveloper.com/t/workaround-for-missing-api-methods-get-all-layercomps/4897>\
**Category:** UXP Plugin API\
**Created:** [July 3, 2022, 5:41am UTC](https://forums.creativeclouddeveloper.com/t/workaround-for-missing-api-methods-get-all-layercomps/4897 "2022-07-03T05:41:08Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![karpiyon](https://avatars.discourse-cdn.com/v4/letter/k/eada6e/32.png) [@karpiyon](https://forums.creativeclouddeveloper.com/u/karpiyon)\
**Post date:** [July 3, 2022, 5:41am UTC](https://forums.creativeclouddeveloper.com/t/workaround-for-missing-api-methods-get-all-layercomps/4897/1 "2022-07-03T05:41:08Z")

</div>

I am trying to get all layercomps names. Since this is still missing in UXP API.

1. I created a simple extendedscript to get this list and write it to file.  
Currently I write this list to the temp folder under: $.getenv(“LocalAppData”).  
%LocalAppData%\Temp\layerscomps.txt.
2. I created an action to run this script.
3. In my UXP plugin I run this action via batchplay.

The problem I am facing, in UXP, is that I can’t read from the temp folder unless the user specifies it with the file picker, which is not an option.

How can write to a file which is accessible to the UXP plugin?  
Or, how can I write to the UXP plugin folder in my extendedscript which would mean passing the UXP plugin path to the script/action, which I think it is not possible?

---

<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:** [July 3, 2022, 7:44am UTC](https://forums.creativeclouddeveloper.com/t/workaround-for-missing-api-methods-get-all-layercomps/4897/2 "2022-07-03T07:44:04Z")

</div>

You could use [`getTemporaryFolder()`](https://developer.adobe.com/photoshop/uxp/2022/uxp/reference-js/Modules/uxp/Persistent%20File%20Storage/FileSystemProvider/#gettemporaryfolder), which IIRC doesn’t require user interaction. Same as `getPluginFolder()` and `getDataFolder()`

But beware, that running scripts from UXP might stop working on any time, even through actions (I think)

> [@Can i run javascript.jsx file using UXP button](http://forums.creativeclouddeveloper.com/t/can-i-run-javascript-jsx-file-using-uxp-button/3006/3):
>
> red_circle Do not do this if you plan on distributing your plugin to others. There is no guarantee that plugins that run JSX like this will continue to work in the future, and your plugin may be removed from the marketplace. Convert to batchPlay and the PS DOM API instead.

---

<div class="post-metadata">

**Author:** ![karpiyon](https://avatars.discourse-cdn.com/v4/letter/k/eada6e/32.png) [@karpiyon](https://forums.creativeclouddeveloper.com/u/karpiyon)\
**Post date:** [July 3, 2022, 8:12am UTC](https://forums.creativeclouddeveloper.com/t/workaround-for-missing-api-methods-get-all-layercomps/4897/3 "2022-07-03T08:12:13Z")

</div>

I intend to start migrating my existing CEP plugin.  
I will use this locally until adobe provide the proper name.  
This is just a temporary solution

---

<div class="post-metadata">

**Author:** ![karpiyon](https://avatars.discourse-cdn.com/v4/letter/k/eada6e/32.png) [@karpiyon](https://forums.creativeclouddeveloper.com/u/karpiyon)\
**Post date:** [July 3, 2022, 11:06am UTC](https://forums.creativeclouddeveloper.com/t/workaround-for-missing-api-methods-get-all-layercomps/4897/4 "2022-07-03T11:06:23Z")

</div>

How do I open a file “myfile.txt” in the temp folder and read it’s content into an array?  
Each line is an element in the array?

` const tempFolder = await fs.getTemporaryFolder();`

---

<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:** [July 3, 2022, 11:42am UTC](https://forums.creativeclouddeveloper.com/t/workaround-for-missing-api-methods-get-all-layercomps/4897/5 "2022-07-03T11:42:03Z")

</div>

If you’re dealing with arrays, you might consider using a JSON files instead. Wouldn’t be any issues figuring out how to parse lines. Sorry, but I don’t have any example on how to parse such structure.

---

<div class="post-metadata">

**Author:** ![karpiyon](https://avatars.discourse-cdn.com/v4/letter/k/eada6e/32.png) [@karpiyon](https://forums.creativeclouddeveloper.com/u/karpiyon)\
**Post date:** [July 3, 2022, 11:53am UTC](https://forums.creativeclouddeveloper.com/t/workaround-for-missing-api-methods-get-all-layercomps/4897/6 "2022-07-03T11:53:11Z")

</div>

I finally got it but it is a cumbersome solution which I will temporarily use until adobe adds this support.

It goes like this:

Preparation:

1. Prepare an extendedScript which generates a list of all layerComps and writes it to tmpFile.  
tmpFile name is read from the layer[0] in the current doc.
2. Create a batchPlay function to run this script

Usage:

1. Generate a new layer whose name equals to the plugin TemporaryFolder. this is now layer[0].
2. Run the batchPlay action to run teh extendedScript.
3. Read tmpFile (which was generated in TemporaryFolder by the extended script)

Complicated but working 🤣

---

<div class="post-metadata">

**Author:** ![AnthonyK](https://avatars.discourse-cdn.com/v4/letter/a/85f322/32.png) [@AnthonyK](https://forums.creativeclouddeveloper.com/u/AnthonyK)\
**Post date:** [July 3, 2022, 6:14pm UTC](https://forums.creativeclouddeveloper.com/t/workaround-for-missing-api-methods-get-all-layercomps/4897/7 "2022-07-03T18:14:09Z")

</div>

You could write the layer comp names to an array and save the array as a global variable in your plugin’s JS. No file writing necessary and easily accessible. This assumes you’ll be using the names during the current Ps session. If you need the names for another Ps session, then the getDataFolder() option should work.

---

<div class="post-metadata">

**Author:** ![karpiyon](https://avatars.discourse-cdn.com/v4/letter/k/eada6e/32.png) [@karpiyon](https://forums.creativeclouddeveloper.com/u/karpiyon)\
**Post date:** [July 3, 2022, 6:30pm UTC](https://forums.creativeclouddeveloper.com/t/workaround-for-missing-api-methods-get-all-layercomps/4897/8 "2022-07-03T18:30:28Z")

</div>

> [@AnthonyK](#):
>
> JS

How do you write that global variable?  
The layercoms are generated in an external extendedscript file?  
Can you show a simple exampe of write this variable and then read it?

---

<div class="post-metadata">

**Author:** ![AnthonyK](https://avatars.discourse-cdn.com/v4/letter/a/85f322/32.png) [@AnthonyK](https://forums.creativeclouddeveloper.com/u/AnthonyK)\
**Post date:** [July 3, 2022, 7:07pm UTC](https://forums.creativeclouddeveloper.com/t/workaround-for-missing-api-methods-get-all-layercomps/4897/9 "2022-07-03T19:07:56Z")

</div>

```auto
var myGlobalVariable = [];

```

This establishes the variable as an array. As long as you don’t put this declaration inside a function, it will be available throughout your JS, both inside and outside the function brackets, { }. This is what makes it a “global” variable.

You then need to use the [JavaScript .push() function](https://www.w3schools.com/jsref/jsref_push.asp) to add data values (layer comp names, in your case) to the array as they are generated.

However, I think your other issue is using extendScript to get the layer comp names. As mentioned elsewhere in this thread, using ExtendScript inside UXP is not a good idea. You should use Alchemist instead. It has a “compsList” property in Documents that looks like it supplies the information you’re looking for. You could iterate through the “compsList” arrary from Alchemist to extract their names and then “push” them into your array, which only contains these names.

---

<div class="post-metadata">

**Author:** ![karpiyon](https://avatars.discourse-cdn.com/v4/letter/k/eada6e/32.png) [@karpiyon](https://forums.creativeclouddeveloper.com/u/karpiyon)\
**Post date:** [July 4, 2022, 5:37am UTC](https://forums.creativeclouddeveloper.com/t/workaround-for-missing-api-methods-get-all-layercomps/4897/10 "2022-07-04T05:37:16Z")

</div>

This is what Alchemist shows when I select a layer comp:

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

const result = await batchPlay(
[
   {
      _obj: "applyComp",
      _target: [
         {
            _ref: "compsClass",
            _name: "Layer Comp 1"
         }
      ],
      _options: {
         dialogOptions: "dontDisplay"
      }
   }
],{
   synchronousExecution: false,
   modalBehavior: "execute"
});

```

Could you elaborate how you suggest I extract the list of all layerComp names with it?

---

<div class="post-metadata">

**Author:** ![AnthonyK](https://avatars.discourse-cdn.com/v4/letter/a/85f322/32.png) [@AnthonyK](https://forums.creativeclouddeveloper.com/u/AnthonyK)\
**Post date:** [July 4, 2022, 6:08pm UTC](https://forums.creativeclouddeveloper.com/t/workaround-for-missing-api-methods-get-all-layercomps/4897/11 "2022-07-04T18:08:24Z")

</div>

When you click on the “Code” option in Alchemist, you get:

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

const result = await batchPlay(
[
   {
      _obj: "get",
      _target: [
         {
            _property: "compsList"
         },
         {
            _ref: "document",
            _id: 219
         }
      ],
      _options: {
         dialogOptions: "dontDisplay"
      }
   }
],{
   synchronousExecution: false,
   modalBehavior: "fail"
});
console.log(result);

```

This is the “getter” for this “compsList” Document property. _NOTE: I don’t think you need the “\_id: 219” part as it would be document specific for my document. Don’t include that._

The

```auto
console.log(result);

```

will display the results in the UXP Developer Tool console.

It’s usually an array of objects, and you’ll need to deconstruct based on what you get in order to find the “title”, which is the name for a particular layer comp. The UXP Developer Tool will show you the “result” via console.log and you can keep clicking the arrows on the left to locate the path to the “title”.

---

<div class="post-metadata">

**Author:** ![karpiyon](https://avatars.discourse-cdn.com/v4/letter/k/eada6e/32.png) [@karpiyon](https://forums.creativeclouddeveloper.com/u/karpiyon)\
**Post date:** [July 9, 2022, 3:38pm UTC](https://forums.creativeclouddeveloper.com/t/workaround-for-missing-api-methods-get-all-layercomps/4897/13 "2022-07-09T15:38:22Z")

</div>

This is what fixed it:

```auto
const getLayerComps = (id) => {
   const result = batchPlay(
      [
         {
            _obj: "get",
            _target: [
               {
                  _property: "compsList"
               },
               {
                  _ref: "document",
                  _id: id
               }
            ],
            _options: {
               dialogOptions: "dontDisplay"
            }
         }
      ], {
      synchronousExecution: true,
      modalBehavior: "wait"
   });
   let lc=result[0].compsList;
   if(typeof lc == "undefined"){
      return [];
   }else{
      return lc.map(comp => comp.title);
   }
}

```
