I am trying to modify original PSD and then delete the original one and only want to save as a new jpg. My code is working fine with this line:
activeDocument.close(SaveOptions.DONOTSAVECHANGES); // Close Original Image
But when I replace above line with this line:
psd.remove(); // I want to delete Original file
It giving me remove() is not a function
error.
Here is the complete script. I have tired to read Photoshop JS Guide 2015 and also google this issue but I didn’t find any answer.
var defaultRulerUnits = preferences.rulerUnits;
preferences.rulerUnits = Units.PIXELS;
if (documents.length >= 1){
var hres = 0;
var vres = 0;
var OldName = activeDocument.name.substring(0, activeDocument.name.indexOf('.'));
var CurrentFolder = activeDocument.path;
var psd = app.activeDocument;
hres = activeDocument.width;
vres = activeDocument.height;
activeDocument.selection.selectAll();
if (activeDocument.layers.length >1) {
activeDocument.selection.copy(true);
}
else{
if (activeDocument.layers.length =1) {
activeDocument.selection.copy(false);
}
}
psd.remove(); // I want to delete Original file
var newDoc = documents.add(hres, vres, 72, OldName, NewDocumentMode.RGB, DocumentFill.WHITE);
newDoc.paste();
jpgFile = new File(CurrentFolder + "/" + OldName+ ".jpg" );
jpgSaveOptions = new JPEGSaveOptions();
jpgSaveOptions.formatOptions = FormatOptions.STANDARDBASELINE;
jpgSaveOptions.matte = MatteType.NONE;
jpgSaveOptions.quality = 12;
newDoc.saveAs(jpgFile, jpgSaveOptions, true, Extension.LOWERCASE);
}
2
Answers
Will delete the active layer. There’s no .remove() method to delete a file.
A little late to the thread, but hope this helps someone else.
The remove method expects a file location. You can accomplish removing the original file like this:
Edit: Meant to also include a link to this handy ESTK reference doc where I learned about working with the File object: http://estk.aenhancers.com/3%20-%20File%20System%20Access/file-object.html?highlight=delete