Reputation: 139
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?
Upvotes: 1
Views: 415
Reputation: 96
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();
}
}
Upvotes: 1
Reputation: 139
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.
Upvotes: 0
Reputation: 4967
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.
Upvotes: 0