Copy link to clipboard
Copied
Haven't touched Javascript in some 10 years. Yikes. Coming from C & Perl, I'm still fumbling about. I've written a crude script to take the current selection, copy, and save to a new file. Problem is, saveAs() always gives me an 8800 Error (General Photoshop Error). Probably the worst kinda since it basically tells you nothing.
I've attached the code. Any help is appreciated. I'm on CS4, btw.
Copy link to clipboard
Copied
Your code is not yet available but this might help..
//IE:-
var example = File("~/FileName.jpg");
SaveJPEG(example,12);
function SaveBMP(savefile){
saveBMP = new BMPSaveOptions();
saveBMP.alphaChannels = false;
saveBMP.depth = BMPDepthType.TWENTYFOUR;
saveBMP.flipRowOrder = false;
saveBMP.rleCompression = false;
saveBMP.osType = OperatingSystem.WINDOWS;
activeDocument.saveAs(saveFile, saveBMP, true, Extension.LOWERCASE);
}
saveTarga(saveFile){
targaSaveOptions = new TargaSaveOptions();
targaSaveOptions.alphaChannels = true;
targaSaveOptions.resolution = TargaBitsPerPixels.TWENTFOUR;
activeDocument.saveAs(saveFile, targaSaveOptions, true, Extension.LOWERCASE);
}
function SaveGIFF(savefile){
gifSaveOptions = new GIFSaveOptions();
gifSaveOptions.colors = 256;
gifSaveOptions.dither = Dither.NONE;
gifSaveOptions.matte = MatteType.NONE;
gifSaveOptions.preserveExactColors = false;
gifSaveOptions.transparency = false;
gifSaveOptions.interlaced = false;
activeDocument.saveAs(saveFile, gifSaveOptions, true,Extension.LOWERCASE);
}
function SaveJPEG(saveFile, jpegQuality){
jpgSaveOptions = new JPEGSaveOptions();
jpgSaveOptions.embedColorProfile = true;
jpgSaveOptions.formatOptions = FormatOptions.STANDARDBASELINE;
jpgSaveOptions.matte = MatteType.NONE;
jpgSaveOptions.quality = jpegQuality; //1-12
activeDocument.saveAs(saveFile, jpgSaveOptions, true,Extension.LOWERCASE);
}
function SaveTIFF(saveFile){
tiffSaveOptions = new TiffSaveOptions();
tiffSaveOptions.embedColorProfile = true;
tiffSaveOptions.alphaChannels = true;
tiffSaveOptions.imageCompression = TIFFEncoding.TIFFLZW;
activeDocument.saveAs(saveFile, tiffSaveOptions, true, Extension.LOWERCASE);
}
function SaveEPS(saveFile){
epsSaveOptions = new EPSSaveOptions();
epsSaveOptions.encoding = SaveEncoding.JPEGHIGH;
activeDocument.saveAs(saveFile,epsSaveOptions, true,Extension.LOWERCASE);
}
function SavePNG(saveFile){
pngSaveOptions = new PNGSaveOptions();
pngSaveOptions.embedColorProfile = true;
pngSaveOptions.formatOptions = FormatOptions.STANDARDBASELINE;
pngSaveOptions.matte = MatteType.NONE;
pngSaveOptions.quality = 1;
pngSaveOptions.PNG8 = false; //24 bit PNG
pngSaveOptions.transparency = true;
activeDocument.saveAs(saveFile, pngSaveOptions, true, Extension.LOWERCASE);
}
function SavePSD(saveFile){
psdSaveOptions = new PhotoshopSaveOptions();
psdSaveOptions.embedColorProfile = true;
psdSaveOptions.alphaChannels = true;
activeDocument.saveAs(saveFile, psdSaveOptions, true, Extension.LOWERCASE);
}
function SavePDF(saveFile){
pdfSaveOptions = new PDFSaveOptions();
activeDocument.saveAs(saveFile, pdfSaveOptions, true, Extension.LOWERCASE);
}
Copy link to clipboard
Copied
Using you SaveJPEG() function, it works... now I just have to figure out the difference. At first glance, I'm doing the same thing. But, obviously there's a discprepency somewhere.
Thanks!
Paul
EDIT: Has to be my filename, no? I'm trying to pass it something like, "/path/to/file.jpg" and it fails (even your SaveJPEG() ).
The essence of mine is:
var save_dir = "/home/paule/thumbnails";
var app_name = curr_doc.name;
var new_name = app_name.replace( ".jpg", "tn.jpg" );
var new_location = save_dir + "/" + new_name;
save_file = new File( new_location ); //ERROR 8800
SaveJPEG( save_file, 10 );
So it doesn't like the path I'm giving it for some reason.
Copy link to clipboard
Copied
That could be your problem as it looks like you are passing a string not a file object..
SaveJPEG("c:/path/fileName.jpg",12); Wrong it is a text string
SaveJPEG(File("c:/path/fileName.jpg"),12); Ok it is now a file object.
Copy link to clipboard
Copied
Okay, I got it.
I'm an idiot.
my homedir is not /home/username on the Mac. Doh.
var save_dir = "/home/paule/thumbnails"; // broken
var save_dir = "~/thumbnails"; // groovy
Wish the error was better. "That directory doesn't exist" or something along those lines would've saved me some time.
One last thing which might need it's own discussion but I'll ask now that I've got your attention:
I add the following line to SaveJPEG() just before it returns;
activeDocument.close( jpgSaveOptions.DONOTSAVECHANGES );
Yet, it prompts me to save changes. 😕
Any idea?
Cheers for the help, btw.
Copy link to clipboard
Copied
Should be:
activeDocument.close( SaveOptions.DONOTSAVECHANGES );
Copy link to clipboard
Copied
Yep, that wroked.
Guess I'm all set. Thanks guys!
Off to bed.