upgrde this script to subfolders
Hi There,
Thanks to this community i've just finished coding this script that:
1.search for psd files in a folder
2. opens the files and does some work with the layer and SO
3. saves the resulting tif in the same folder of the psd
I would try to upgrade this script to work also on subfolders... do you think is possibile?
the folder structure is
- Product name (folder)
- product code XXX (folder)
- filexxx.psd
- fileyyy.psd
- filezzz.psd
- product code YYY (folder)
- filexxx.psd
- fileyyy.psd
- filezzz.psd
Right now i'm able to launch the script for every product code folder. i would like to launch it on the Product name folder and let it work on every subfolders..
here's the code
// JavaScript Document
var destFolder, sourceFolder, files, fileType, sourceDoc, targetFile, pdfSaveOpts;
var i = 0;
// Select the source folder.
sourceFolder = Folder.selectDialog( 'Seleziona la cartella di origine');
// If a valid folder is selected
if ( sourceFolder != null )
{
files = new Array();
fileType = "*.psd"; //prompt( 'Select type of photoshop files to you want to process. Eg: *.psd', ' ' );
// Get all files matching the pattern
files = sourceFolder.getFiles( fileType );
if ( files.length > 0 )
{
// Get the destination to save the files
//destFolder = Folder.selectDialog( 'Select the folder where you want to save the converted .tif files.', '~' );
destFolder = sourceFolder;
for ( i = 0; i < files.length; i++ )
{
sourceDoc = app.open(files); // returns the document object
var docRef = sourceDoc;
with (docRef) {
chiusuraPesa();
}
}
}
}
function chiusuraPesa(){
cercaShadow();
searchSO(); //cerca style
openSO(); //apre oggetto avanzato
applicaVisibile(); // applica visibile, via tracciati e canali, salva e chiude l'oggetto avanzato
salvaTiffDEF(); //salva il tiff definitivo
}
function cercaShadow(){
var srcDoc = app.activeDocument;
srcDoc.channels.removeAll();
var layerSetRef = srcDoc.layerSets.getByName("shadow");
//srcDoc.activeLayer = srcDoc.layers.getByName("style");
layerSetRef.merge();
var layerSetRef = srcDoc.layers.getByName("shadow");
srcDoc.activeLayer = layerSetRef ;
hasMask();//controlla se esiste una maschera di livello su shadow e in tal caso la cancella
}
function hasMask() {
var srcDoc = app.activeDocument;
var lm = true, pmd;
try {
pmd = srcDoc.activeLayer.layerMaskDensity;
srcDoc.activeLayer.layerMaskDensity = 50.0;
srcDoc.activeLayer.layerMaskDensity = pmd;
} catch(e) { lm = false };
if (lm == true) {
function sTT(v) {return stringIDToTypeID(v)}
(ref = new ActionReference()).putEnumerated
(sTT('channel'), sTT('channel'), sTT('mask'));
(dsc = new ActionDescriptor()).putReference(sTT('null'), ref)
executeAction(sTT('select'), dsc);
var idDlt = charIDToTypeID( "Dlt " );
var desc110 = new ActionDescriptor();
var idnull = charIDToTypeID( "null" );
var ref49 = new ActionReference();
var idChnl = charIDToTypeID( "Chnl" );
var idOrdn = charIDToTypeID( "Ordn" );
var idTrgt = charIDToTypeID( "Trgt" );
ref49.putEnumerated( idChnl, idOrdn, idTrgt );
desc110.putReference( idnull, ref49 );
var idAply = charIDToTypeID( "Aply" );
desc110.putBoolean( idAply, true );
executeAction( idDlt, desc110, DialogModes.NO );
}
};
function searchSO(){
var srcDoc = app.activeDocument;
srcDoc.activeLayer = srcDoc.layers.getByName("style");
}
function openSO (){
var idplacedLayerEditContents = stringIDToTypeID( "placedLayerEditContents" );
var desc7 = new ActionDescriptor();
executeAction( idplacedLayerEditContents, desc7, DialogModes.NO );
}
function applicaVisibile(){
var newLayer = activeDocument.artLayers.add();
var idMrgV = charIDToTypeID( "MrgV" );
var desc3 = new ActionDescriptor();
var idDplc = charIDToTypeID( "Dplc" );
desc3.putBoolean( idDplc, true );
executeAction( idMrgV, desc3, DialogModes.NO );
var newDoc = app.activeDocument;
newDoc.activeLayer.name = "Complete";
var quota = "quota";
var layName = newDoc.activeLayer.name;
var l = Number(newDoc.layers.length)+1;
while(--l){
if(newDoc.layers[l-1].name!=layName && newDoc.layers[l-1].name!=quota){
newDoc.layers[l-1].remove();
}
else{continue;}
}
newDoc.pathItems.removeAll();
newDoc.channels.removeAll();
newDoc.save();
newDoc.close();
}
function salvaTiffDEF(){
tiffFile = new File(activeDocument.path + "/" + activeDocument.name )
tiffSaveOptions = new TiffSaveOptions()
TiffSaveOptions.embedColorProfile = true
TiffSaveOptions.layers = true
TiffSaveOptions.imageCompression = TIFFEncoding.TIFFLZW
app.activeDocument.saveAs(tiffFile, tiffSaveOptions, true, Extension.LOWERCASE)
app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);
}
Thank you in advance to all of you
