0
determine if file has never been saved in javascript
Community Expert
,
/t5/photoshop-ecosystem-discussions/determine-if-file-has-never-been-saved-in-javascript/td-p/1095386
Jan 03, 2009
Jan 03, 2009
Copy link to clipboard
Copied
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?
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?
TOPICS
Actions and scripting
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
Explore related tutorials & articles
Valorous Hero
,
/t5/photoshop-ecosystem-discussions/determine-if-file-has-never-been-saved-in-javascript/m-p/1095387#M447931
Jan 03, 2009
Jan 03, 2009
Copy link to clipboard
Copied
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?
http://www.ps-scripts.com/bb/viewtopic.php?t=2306
You might be able to utilize some of the code?
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
Valorous Hero
,
/t5/photoshop-ecosystem-discussions/determine-if-file-has-never-been-saved-in-javascript/m-p/1095388#M447932
Jan 03, 2009
Jan 03, 2009
Copy link to clipboard
Copied
Forgot to say this is for JPGs only.
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
Explorer
,
/t5/photoshop-ecosystem-discussions/determine-if-file-has-never-been-saved-in-javascript/m-p/1095389#M447934
Jan 03, 2009
Jan 03, 2009
Copy link to clipboard
Copied
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;
};
(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;
};
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
Valorous Hero
,
/t5/photoshop-ecosystem-discussions/determine-if-file-has-never-been-saved-in-javascript/m-p/1095390#M447935
Jan 03, 2009
Jan 03, 2009
Copy link to clipboard
Copied
Very nice X, I had read the question wrongly, that's what happens when you get to be an old age pensioner!
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
c.pfaffenbichler
AUTHOR
Community Expert
,
/t5/photoshop-ecosystem-discussions/determine-if-file-has-never-been-saved-in-javascript/m-p/1095391#M447936
Jan 04, 2009
Jan 04, 2009
Copy link to clipboard
Copied
Thanks, both of You!
Hopefully I will remember to consult the stlib before asking in the future
Hopefully I will remember to consult the stlib before asking in the future
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
Guru
,
/t5/photoshop-ecosystem-discussions/determine-if-file-has-never-been-saved-in-javascript/m-p/1095392#M447937
Jan 04, 2009
Jan 04, 2009
Copy link to clipboard
Copied
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
// 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
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
c.pfaffenbichler
AUTHOR
Community Expert
,
LATEST
/t5/photoshop-ecosystem-discussions/determine-if-file-has-never-been-saved-in-javascript/m-p/1095393#M447938
Jan 04, 2009
Jan 04, 2009
Copy link to clipboard
Copied
Thanks, Mike.
Ive got it to work already.
Ive got it to work already.
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more

