Skip to main content
c.pfaffenbichler
Community Expert
Community Expert
January 3, 2009
Question

determine if file has never been saved in javascript

  • January 3, 2009
  • 7 replies
  • 1681 views
Once again I have a question regarding a way to determine some quality in Photoshop:
Suppose I want to save all files that have been newly created and have not yet been saved in Photohop.
The saved-criterion would also include files that have been changed since the last save, so I thought the absence of a file-path would make for a good distinguishing characteristic; I only managed to successfully use that in a try-catch-clause though, which is bad form Ive been told:
Is there another way to identify a document that has never been saved?
This topic has been closed for replies.

7 replies

c.pfaffenbichler
Community Expert
Community Expert
January 5, 2009
Thanks, Mike.
Ive got it to work already.
Inspiring
January 4, 2009
If I understand your question fully. I would do something like this:

// check doc status
if( ! activeDocument.saved ) {
if(isDocumentNew()){// X's function
//sample code to handle a new doc
var f = new File('/c/temp/temp.psd');
activeDocument.saveAs(f);
}else{
//sample code to handle a changed doc
activeDocument.save();
}
}
// now saple code to handle all doc as saved
activeDocument.close();

Mike
c.pfaffenbichler
Community Expert
Community Expert
January 4, 2009
Thanks, both of You!
Hopefully I will remember to consult the stlib before asking in the future  
Paul Riggott
Inspiring
January 3, 2009
Very nice X, I had read the question wrongly, that's what happens when you get to be an old age pensioner!
Known Participant
January 3, 2009
The try/catch technique is the simplest. The other way looks like this:
(extracted from xtools/xlib/stdlib.js)

-X

function isDocumentNew(doc){
// assumes doc is the activeDocument

cTID = function(s) { return app.charIDToTypeID(s); }


var ref = new ActionReference();
ref.putEnumerated( cTID("Dcmn"),
cTID("Ordn"),
cTID("Trgt") ); //activeDoc
var desc = executeActionGet(ref);

var rc = true;
if (desc.hasKey(cTID("FilR"))) { //FileReference
var path = desc.getPath(cTID("FilR"));
if (path) {
rc = (path.absoluteURI.length == 0);
}
}
return rc;
};
Paul Riggott
Inspiring
January 3, 2009
Forgot to say this is for JPGs only.
Paul Riggott
Inspiring
January 3, 2009
Here is a script that I wrote to test if a file has been saved by Photoshop. If it has it will tell you what quality etc..
http://www.ps-scripts.com/bb/viewtopic.php?t=2306
You might be able to utilize some of the code?