Hello,
is it possible for a script (maybe via Bridge) to delete the current opened file?
thanks.
Carlos
I think this practice would be risky as there is no indo, but you could try this:
#target photoshop
var theString = app.activeDocument.path+"/"+app.activeDocument.name;
new File(theString).remove();
If you want to move it to the trash, maybe changePath would work, but you’d probably have to define the proper path for the volume on which the file resides.
I have to disagree with Chris Cox. There is a loose relation to the file if one exists. If Photoshop 'knows' there is no file associated with the activeDocument the Revert menuItem is grayed out. If the file is deleted after Photoshop opens the document Revert is not grayed out but using it will throw an error.
The document ActionDescriptor also is effected by whether Photoshop 'thinks' there is a related file. There is a key in that descriptor that only exists when there is a file associated with the file. And you can use that key to guarantee that the document has a file on disk.
function hasFile(){
var ref = new ActionReference();
ref.putEnumerated( charIDToTypeID("Dcmn"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );
var desc = executeActionGet(ref);
var res = desc.hasKey(stringIDToTypeID('fileReference')) ? File(desc.getPath(stringIDToTypeID('fileReference'))).exists: false;
return res;
}
I do understand the point Chris is trying to make. Photoshop does not work on files. It only uses the file to create a document.
North America
Europe, Middle East and Africa
Asia Pacific