Hello,
For some time I have been trying to figure out a problem I am having with a script.
I have succeeded to write a script that does exactly what I want, wich is having Photoshop opening selected files, then apply the clipping path and finaly save as .png
The only problem I am experiencing is when Photoshop (CS 5.5) opens the selected number of files, it only applies the script to the first opened file, while the others remain unedited...
I was hoping to find some help and or a solution in solving this problem.
Thanks a lot in advance!
Kind regards,
#target photoshop
//Input selection
var myInputFolder = Folder.selectDialog ("INPUT");
if(myInputFolder!=null){
var myFiles = myInputFolder.getFiles(/.(jpg|psd|tif|png)$/i);
for(var fileIndex=0;fileIndex<myFiles.length;fileIndex++){
var tempDoc = app.open(myFiles[fileIndex]);
}
}
//Track
docs = app.documents;
for (i=0; i < docs.length; i++) {
doc = docs[i];
app.activeDocument = doc;
};
//Unlock Layer
docLay=app.activeDocument.layers;
l=app.activeDocument.layers.length;
while (l>0) {
l--;
docLay[l].isBackgroundLayer = false;
docLay[l].allLocked = false;
}
//Clipping path
if (app.documents.length > 0) {
if (app.activeDocument.pathItems.length > 0) {
var thePath = app.activeDocument.pathItems[0];
app.activeDocument.selection.selectAll();
thePath.makeSelection(0, true, SelectionType.DIMINISH);
}
};
//Clear Selection
try {
app.activeDocument.selection.clear();
} catch(e) {
alert("Sorry, dit document bevat geen pad!");
}
//Resolution
var doc = activeDocument;
var res = doc.resolution;
doc.resizeImage(undefined, undefined, 150, ResampleMethod.BICUBIC);
//Trim
app.activeDocument.trim()
//Save PNG
var doc = app.activeDocument;
var Path = doc.path;
var Name = doc.name.replace(/\.[^\.]+$/, '');
var Suffix = "_DSok";
var saveFile = File(Path + "/" + Name + Suffix + ".png");
SavePNG(saveFile);
function SavePNG(saveFile){
pngSaveOptions = new PNGSaveOptions();
activeDocument.saveAs(saveFile, pngSaveOptions, true, Extension.LOWERCASE);
activeDocument.close(SaveOptions.DONOTSAVECHANGES);
}