Hi there,
I have this script that served me well over the years, but now failing since I installed CS5 on my new mac.
The script export web images based on various criteria...
Images are exported in a folder whose name is based on the processed files...
From what I can tell, the script can't created the folder anymore, causing the image export to fail...
I've looked at the folder.create(); and it return TRUE, even if there's no 'physical' folder created.
I've tried with folders already created and the script ran just fine, which point me to some writing permission issues, but I'm less than sure...
As usual, this script is a big production time saver... Any input on how I can fix this will be redeem with endless virtual cheers
This is working fine with CS3 on mac and PC, but failing on my new mac with CS5...
Here the part that hangs (full code below...):
Code: Select all
var folderName = docRef.name.substring(0, 7);
var fileFolder = new Folder(outputFolder+"/"+folderName); // Create folder named as fileName
if(!fileFolder.exists) fileFolder.create();
var jpgFile = new File(fileFolder + "/" + fileName + suffix + extension);
if (!jpgFile.exists)
{
docRef.exportDocument(jpgFile, ExportType.SAVEFORWEB, saveOptions);
}
Now the complete thing-y:
Code: Select all
// export settings
function exportImage(quality,width,height,suffix,extension)
{
var saveOptions = new ExportOptionsSaveForWeb();
saveOptions.quality = quality;
saveOptions.format = SaveDocumentType.JPEG;
var targetWidth = new UnitValue(width,"px");
var targetHeight = new UnitValue(height,"px");
docRef.resizeImage(targetWidth,targetHeight);
//Bunch of names lookup to figure out the image orientation
try
{
if (docRef.name.indexOf ("000", 0) != -1 || docRef.name.indexOf ("315", 0) != -1 || docRef.name.indexOf ("045", 0) != -1)
{
var fileName = docRef.name.substring(0, 11);
}
else
{
if (docRef.name.indexOf ("135", 0) != -1 || docRef.name.indexOf ("180", 0) != -1 || docRef.name.indexOf ("225", 0) != -1)
{
var fileName = docRef.name.substring(0, 11) + "d";
}
else
{
if (docRef.name.indexOf ("d", 11) == -1) // Check for already flagged "back" images
{
var fileName = docRef.name.substring(0, 11);
}
else
{
var fileName = docRef.name.substring(0, 12);
}
}
}
var folderName = docRef.name.substring(0, 7);
var fileFolder = new Folder(outputFolder+"/"+folderName); // Create folder named as fileName
if(!fileFolder.exists) fileFolder.create();
var jpgFile = new File(fileFolder + "/" + fileName + suffix + extension);
if (!jpgFile.exists)
{
alert(fileFolder + "/" + fileName + suffix + extension);
docRef.exportDocument(jpgFile, ExportType.SAVEFORWEB, saveOptions);
}
}
catch (e)
{
alert("Error encountered when saving the image (" + fileName + suffix + extension + ")! \r\r" + e);
}
}
//
// Main instructions
var startDisplayDialogs = app.displayDialogs; // Save the current preferences
app.displayDialogs = DialogModes.NO; // Set Photoshop to use pixels and display no dialogs
app.preferences.typeUnits = TypeUnits.PIXELS;
var inputFolder = Folder.selectDialog("Select the folder containing the source images") // ask the user for the input folder
var outputFolder = Folder.selectDialog("Select a folder for the output images") // ask the user for the output folder
// see if we got something interesting from the dialog
if (inputFolder != null && outputFolder != null)
{
var fileList = inputFolder.getFiles();
// get all the files found in this folder
for (var i = 0; i < fileList.length; i++)
{
try {
// open each one in turn
if (fileList instanceof File && fileList.hidden == false) // The fileList includes both folders and files so open only files
{
var docRef = open(fileList) // get a reference to the new document
var docWidth = docRef.width.value;
var docHeight = docRef.height.value;
var bgColor = new SolidColor(); //set bgColor to white
bgColor.rgb.red = 255;
bgColor.rgb.green = 255;
bgColor.rgb.blue = 255;
app.backgroundColor = bgColor;
//resize canvas to a 1:1 ratio
if ( docWidth > docHeight )
{
docRef.resizeCanvas(docWidth,docWidth);
}
else
{
docRef.resizeCanvas(docHeight,docHeight);
}
//Make images...
exportImage(60,300,300,"",".jpg"); // Large image
if (docRef.name.indexOf ("d", 0) == -1) // Large back image
{
exportImage(60,75,75,"_th",".jpg"); // Thumbnail image
}
docRef.close(SaveOptions.DONOTSAVECHANGES);
}
}
catch (e)
{
var file = new File('~/ps-error.log'); //this is your error report!
file.open('e');
file.writeln (e);
file.close();
}
}
}
//Run the job
app.displayDialogs = startDisplayDialogs