# Make active document by name

**URL:** <https://forums.creativeclouddeveloper.com/t/make-active-document-by-name/2930>\
**Category:** UXP Plugin API\
**Created:** [May 11, 2021, 9:24am UTC](https://forums.creativeclouddeveloper.com/t/make-active-document-by-name/2930 "2021-05-11T09:24:58Z")\
**Posts on this page:** 3\
**Page:** 1

<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:** [May 11, 2021, 9:24am UTC](https://forums.creativeclouddeveloper.com/t/make-active-document-by-name/2930/1 "2021-05-11T09:24:59Z")

</div>

I’m trying to figure out how to check to see if a document is open, and if it is to make it the active one. I don’t know how to check the open documents titles to get their current \_id. I can loop through them and check their title and this works, although ideally there is a better solution. Current code is below

```
async function testCode1() {

   if (app.activeDocument.title != "3D_temp.tif") {

      for (i = 0; i < app.documents.length; i++) {

         app.activeDocument = app.documents[i]

         if (app.activeDocument.title == "3D_temp.tif") {

            return

         } 

      }

   }

}
```

---

<div class="post-metadata">

**Author:** ![svumme](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.creativeclouddeveloper.com/svumme/32/1289_2.png) [@svumme](https://forums.creativeclouddeveloper.com/u/svumme)\
**Post date:** [May 11, 2021, 10:14am UTC](https://forums.creativeclouddeveloper.com/t/make-active-document-by-name/2930/2 "2021-05-11T10:14:03Z")

</div>

Hi, if I understand correctly you would like to select the document by the name, try this way :

```
async function selectByName(name){

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

    const result= await batchPlay(

    [

       {

          "_obj": "select",

          "_target": [

             {

                "_ref": "document",

                "_name": name

             }

          ],

        

          "_isCommand": true,

          "_options": {

             "dialogOptions": "silent"

          }

       }

    ],{

       "synchronousExecution": false,

       "modalBehavior": "fail"

    });

    if(result[0].message!=undefined){

    console.log("the document does not exist")
    }else{}
    }

    selectByName(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:** [May 13, 2021, 12:44pm UTC](https://forums.creativeclouddeveloper.com/t/make-active-document-by-name/2930/3 "2021-05-13T12:44:39Z")

</div>

Amazing, thank you so much. So obvious once you point it out.
