.remove() 不是 Photoshop CC 2017 ExtendScript 工具包中的函数错误

.remove() is not a function error in Photoshop CC 2017 ExtendScript Tool Kit

我想修改原来的PSD,然后删除原来的,只想另存为新的jpg。我的代码在这一行中运行良好:

activeDocument.close(SaveOptions.DONOTSAVECHANGES); // Close Original Image

但是当我用这一行替换上面的行时:

psd.remove(); // I want to delete Original file

它给我 remove() is not a function 错误。

这是完整的脚本。我厌倦了阅读 Photoshop JS Guide 2015 和 google 这个问题,但我没有找到任何答案。

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);

}

 srcDoc.activeLayer.remove();

将删除活动图层。没有删除文件的 .remove() 方法。

线程有点晚了,但希望这对其他人有所帮助。

remove 方法需要一个文件位置。您可以像这样完成删除原始文件:

var activeDoc = app.activeDocument;
var docPath = new Folder(activeDoc.path);
var psd = new File(docPath + "/" + activeDoc.name);
...
psd.remove();

编辑:还打算在这个方便的 ESTK 参考文档中包含一个 link,我在其中学习了如何使用 File 对象:http://estk.aenhancers.com/3%20-%20File%20System%20Access/file-object.html?highlight=delete