Photoshop Javascript 脚本保存和关闭文档
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10795983/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Photoshop Javascript scripting saving and closing document
提问by Barney
I'm having trouble saving for some reason; I'm using Photoshop CS5.1 (if that really is the cause of the issue)
由于某种原因,我在储蓄方面遇到了困难;我正在使用 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);
I'd like the script to save and close, but I keep getting this error. I'm using Photoshop CS5.1 (if that really is the cause of the issue)
我希望脚本保存并关闭,但我不断收到此错误。我正在使用 Photoshop CS5.1(如果这确实是问题的原因)
回答by pdizz
When you get the error General Photoshop error
while saving it usually means a problem with the save path. Photoshop is trying to save to a location that doesn't exist. This works assuming the folder C:/Users/Barney/Pictures/Temp001
exists:
当您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);
The only changes I made were to to the path string saveFile = new File("C:/Users/Barney/Pictures/Temp001/" + thistimestamp)
Notice I added the C:
to make it an absolute path and added a /
after Temp001 to specify this is a folder and not part of the final file name. My Pictures
should actually be Pictures
(my pictures is just an alias), which is what you get if you copy the address from the address bar. Also I removed the + ".jpeg"
because photoshop takes care of the file extension for you.
我所做的唯一更改是对路径字符串saveFile = new File("C:/Users/Barney/Pictures/Temp001/" + thistimestamp)
注意我添加了C:
使其成为绝对路径并/
在 Temp001 之后添加了一个以指定这是一个文件夹而不是最终文件名的一部分。My Pictures
实际上应该是Pictures
(我的图片只是一个别名),这就是您从地址栏中复制地址时得到的。我还删除了 ,+ ".jpeg"
因为 Photoshop 会为您处理文件扩展名。
If you're trying to create a new folder you have to use the Folder
object:
如果您尝试创建新文件夹,则必须使用该Folder
对象:
var myfolder = new Folder("c:/Users/Barney/Pictures/Temp001/");
myfolder.create();