if (app.documents.length != 0) {
var doc= app.activeDocument;
for (i = 0; i < 5; i++) {
var layer = doc.artLayers[0]
layer.textItem.contents = i;
var pngFile = new File("/Users/dlokshin/temp/" + i + ".png");
pngSaveOptions = new PNGSaveOptions();
pngSaveOptions.interlaced = false;
doc.saveAs(pngFile, pngSaveOptions, true, Extension.LOWERCASE);
}
}
每当我运行上面的脚本时,不是将文件保存为1.png,2.png,3.png等,而是打开保存对话框并提示我输入文件名并单击“保存”。我做错了什么?
答案 0 :(得分:7)
在为photoshop编写脚本时,显然保存PNG与保存JPEG非常不同。以下适用于PNG:
if (app.documents.length != 0) {
var doc= app.activeDocument;
for (i = 0; i < 5; i++) {
var layer = doc.artLayers[0]
layer.textItem.contents = i;
var opts, file;
opts = new ExportOptionsSaveForWeb();
opts.format = SaveDocumentType.PNG;
opts.PNG8 = false;
opts.quality = 100;
pngFile = new File("/Users/dlokshin/temp/speed.png");
app.activeDocument.exportDocument(pngFile, ExportType.SAVEFORWEB, opts);
}
}
答案 1 :(得分:1)
如果我向Photoshop提供如下保存路径,则PNGSaveOptions
保存对我有用:
var doc = app.activeDocument;
var filePath = activeDocument.fullName.path;
var pngFile = File(filePath + "/" + "myname.png");
pngSaveOptions = new PNGSaveOptions();
doc.saveAs(pngFile, pngSaveOptions, true, Extension.LOWERCASE);
答案 2 :(得分:0)
只需在开头输入
即可app.displayDialogs = DialogModes.NO;
你不会再得到对话了。