skip to Main Content

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?

3

Answers


  1. Chosen as BEST ANSWER

    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.


  2. 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.

    Login or Signup to reply.
  3. 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();
       }
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search