Photoshop Javascript scripting saving and closing document

Deadly 提交于 2019-12-09 01:38:04

问题


I'm having trouble saving for some reason; I'm using Photoshop CS5.1 (if that really is the cause of the issue)

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)


回答1:


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:

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.

If you're trying to create a new folder you have to use the Folder object:

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


来源:https://stackoverflow.com/questions/10795983/photoshop-javascript-scripting-saving-and-closing-document

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!