I've been working on a script that would help a friend of mine to prep photos for his web-site. It was working just fine until after some small change it suddenly started telling me this: "Cannot open the file because the open options are incorrect". The ExtendScript Toolkit highlights line 44: var doc = app.open(file);
I've looked at all variations of the app.open(); function but can't seem to understand what is wrong.
I'm hoping someone will notice the problem. Thanks in advance!
#target photoshop
var outputWidth = 1500;
alert("You will now need to select a folder with photos to be processed.");
var inputFolder = Folder.selectDialog("Select Input folder");
// Creating a new subfolder based on user input
var outputFolder = new Folder(inputFolder + "/" + "PROCESSED");
outputFolder.create();
var Destination = outputFolder.path + "/" + outputFolder.name;
// Replacing %20 with space for clean alert
var CleanDestination = Destination.replace('%20', ' ');
var CleanerDestination = CleanDestination.replace('%20', ' ');
var startRulerUnits = preferences.rulerUnits;
app.preferences.rulerUnits = Units.PIXELS;
// our web export options
var options = new ExportOptionsSaveForWeb();
options.quality = 70;
options.format = SaveDocumentType.JPEG;
options.optimized = false;
options.includeProfile = true;
if (inputFolder != null && outputFolder != null) { var files = inputFolder.getFiles(); for (var i = 0; i < files.length; i++) { var file = files[i]; var doc = app.open(file); // get a reference to the current (active) document and store it in a variable named "doc" doc = app.activeDocument; //get the filename without the extension var Name = app.activeDocument.name.replace(/\.[^\.]+$/, ''); if (doc.height > 1000) {
//build up the output file name and path var goodFolder = new Folder(outputFolder + "/" + "READY FOR WEB"); goodFolder.create(); var saveFile = File(goodFolder + "/" + Name + "-web" + ".jpg");
// do the resizing. if height > width (portrait-mode) resize based on height. otherwise, resize based on width if (doc.height > doc.width) { doc.resizeImage(null,UnitValue(outputWidth,"px"),null,ResampleMethod.BICUBIC); } else { doc.resizeImage(UnitValue(outputWidth,"px"),null,null,ResampleMethod.BICUBIC); }
}
else { //build up the output file name and path var smallFolder = new Folder(outputFolder + "/" + "TOO SMALL"); smallFolder.create(); var saveFile = File(smallFolder + "/" + Name + ".jpg");
} doc.convertProfile('sRGB IEC61966-2.1', Intent.RELATIVECOLORIMETRIC, true, true); //you need to have a full filepath not a folder doc.exportDocument(/*outputFolder */saveFile, ExportType.SAVEFORWEB, options); doc.close(SaveOptions.DONOTSAVECHANGES); $.writeln('File ' + (i + 1) + ' of ' + files.length + ' processed'); }
//restore ruler units
app.preferences.rulerUnits = startRulerUnits;
alert(files.length + " files have been processed into " + CleanerDestination);
}