Skip to main content
Inspiring
January 11, 2023
Question

activeDocument array?

  • January 11, 2023
  • 1 reply
  • 1546 views

Does Photoshop keep an array of it's activeDocuments? Not a list of the documents history, which is held in  documents. But Photoshop files that are currently open. So app.activeDocument[1] would be the document you used last and app.activeDocument[0] is the current one.

 

for (var i = 0; i < activeDocuments.length; i++)
{
 // Something
}

Obviously the above doesn't work. - But you get the idea.

 

Hopefully.

 

This topic has been closed for replies.

1 reply

Legend
January 11, 2023

Only one document can be active at one time. So, no, that is not stored in an array, just an application property.

You might be looking for app.documents instead, which has nothing to do with history.

 

Inspiring
January 12, 2023

 

var theDocs = app.documents;

for (var i = 0; i < theDocs.length; i++)
{
  msg += theDocs[i].name + "\n";
}
alert(msg)

That gives the cocuments that wer opened in order, which not quite what I was after. I'm sure I'll work something out.

Legend
January 12, 2023

You can write a script using notifications. Each time you switch to a new document, it will record its ID. Accordingly, having saved this data during the session, you can always restore the sequence of switching between documents. Closed documents can simply be skipped.

 

I wrote a script designed to be written to an action that allows you to remember a specific document and return to it later. Perhaps this will help you: How to change the order of open documents for an action?