1

During the course of my work I am constantly in a position where I would like to close all the documents that I have open except the templates I am working with.

If I were to have the word "keep" in each of my template document names, how would I go about writing some javascript code to run in photoshop that will close all open documents that DO NOT have the word "keep" in their names?

mort
  • 12,988
  • 14
  • 52
  • 97
Andrew Hall
  • 139
  • 7

3 Answers3

1

What you need to do is grab the Documents array and iterate through them. This code should do the trick. The search phrase is case sensitive.

var docs = app.documents;

for(var i = docs.length - 1; i >= 0; i--){
   if(docs[i].name.indexOf('keep') < 0){
      docs[i].close();
   }
}
Daikazu
  • 96
  • 3
0

It sounds like you wish to

But then again, I'm probably forgetting some edge cases since I haven't tried this specifically.

Start with something small, get it working and come back with specific questions when they appear if you can't find an answer to the specific questions.

Community
  • 1
  • 1
Jonast92
  • 4,964
  • 1
  • 18
  • 32
0

As it turns out there was an easy way to avoid the part that I was not sure how to proceed with...

Performing the desired operation on a single document is easy:

 if (activeDocument.name !="keep") activeDocument.close(SaveOptions.DONOTSAVECHANGES);

What was confusing me was how to write a script that would perform this operation on EVERY open document. I quickly realized that this could easily be taken care of by recording an action playing this simple script and batching the action on all open files in photoshop.

Andrew Hall
  • 139
  • 7