Photoshop Javascript 脚本保存和关闭文档

Photoshop Javascript scripting saving and closing document

本文关键字:文档 保存 Javascript 脚本 Photoshop      更新时间:2023-09-26

由于某种原因,我在保存时遇到问题;我正在使用Photoshop CS5.1(如果这确实是问题的原因)

error 8800: General Photoshop error occurred. 
This functionality may not be available in this version of Photoshop.
Could not save a copy as C:'...'Temp001.jpeg0011338281522" 
because the file could not be found


var thistimestamp = Math.round(new Date().getTime() / 1000);
saveFile = new File( "/Users/Barny/My Pictures/Temp001" +thistimestamp+ ".jpeg" )
saveOptions = new JPEGSaveOptions();
saveOptions.embedColorProfile = true;
saveOptions.formatOptions = FormatOptions.STANDARDBASELINE;
saveOptions.matte = MatteType.NONE;
saveOptions.quality = 9;
app.activeDocument.saveAs(saveFile, saveOptions, true,Extension.LOWERCASE);

我希望脚本保存并关闭,但我不断收到此错误。我正在使用Photoshop CS5.1(如果这确实是问题的原因)

当您在

保存时General Photoshop error收到错误通常意味着保存路径有问题。Photoshop 正在尝试保存到不存在的位置。假设文件夹C:/Users/Barney/Pictures/Temp001存在,则此方法有效:

var thistimestamp = Math.round(new Date().getTime() / 1000);
saveFile = new File( "c:/Users/Barney/Pictures/Temp001/" +thistimestamp)
saveOptions = new JPEGSaveOptions();
saveOptions.embedColorProfile = true;
saveOptions.formatOptions = FormatOptions.STANDARDBASELINE;
saveOptions.matte = MatteType.NONE;
saveOptions.quality = 9;
app.activeDocument.saveAs(saveFile, saveOptions, true,Extension.LOWERCASE);

我所做的唯一更改是对路径字符串的更改,saveFile = new File("C:/Users/Barney/Pictures/Temp001/" + thistimestamp)请注意,我添加了C:以使其成为绝对路径,并在 Temp001 之后添加了一个/以指定这是一个文件夹,而不是最终文件名的一部分。 My Pictures实际上应该是Pictures的(我的照片只是一个别名),这就是你从地址栏复制地址时得到的。我还删除了+ ".jpeg",因为 photoshop 会为您处理文件扩展名。

如果您尝试创建新文件夹,则必须使用 Folder 对象:

var myfolder = new Folder("c:/Users/Barney/Pictures/Temp001/");
myfolder.create();