Testing for the Existence of an Unsaved Document

Discussion of Photoshop Scripting, Photoshop Actions and Photoshop Automation in General

Moderators: Tom, Kukurykus

Andrew

Testing for the Existence of an Unsaved Document

Post by Andrew »

There is at least a little bit of sense to this madness.

Start off with an open image, duplicate it and close the original.

Allow for user intervention which might or might not close the duplicate without saving.

Now you want to close the document IF it is still open (and you don't want to close other documents if they happen to be open).

I don't think it can be done. If you assign:

var dupe = activeDocument;

Then, if dupe has been closed, any attempt to do anything with dupe leads to an error - an error that is not caught by try / catch.

You can test to see if dupe.name is amongst the documents list, but this is not necessarily unique as it has no path attached, and because dupe was never saved, dupe.fullName cannot be accessed.

One of those frustrated raves, ignore...

Andrew
Mike Hale

Testing for the Existence of an Unsaved Document

Post by Mike Hale »

This might be more trouble than it's worth, but could you put a keyword like AH-Dupe in the metadata before you turned it over to the user.

When they are done, search the open docs for your keyword
Andrew

Testing for the Existence of an Unsaved Document

Post by Andrew »

Hey, that's my kindofa kluge, I like it

Andrew
xbytor

Testing for the Existence of an Unsaved Document

Post by xbytor »

Another way to approach the problem is to just set an attribute on the dupe object.

Code: Select allvar dupe = activeDocument;
dupe.isDupe = true;

// do stuff here

// close any open dupes
for (var i = 0; i < app.documents.length; i++) {
   if (app.documents.isDupe) {
      app.documents.close();
   }
}
Andrew

Testing for the Existence of an Unsaved Document

Post by Andrew »

Brilliant Xbytor, that's what I'm looking for. I tried all sorts of tests using documents but didn't find that one. Thanks

Andrew