Barney
Barney

Reputation: 1848

Photoshop Javascript scripting saving and closing document

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)

Upvotes: 2

Views: 12922

Answers (1)

pdizz
pdizz

Reputation: 4240

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

Upvotes: 6

Related Questions