JSX Batch Processing Recursive Folders?

Discussion of Automation, Image Workflow and Raw Image Workflow

Moderators: Tom, Kukurykus

soupking
Posts: 1
Joined: Wed Mar 08, 2017 7:29 pm

JSX Batch Processing Recursive Folders?

Post by soupking »

Hi everybody,

Long time Flash Designer (actionscript), Photoshop production artist and I've stumbled into the world of Javascripting for Photoshop. :shock:

I've landed here because a colleague needed 80 images sized down, with square 1x1 aspect ratio bleed at 1000 px wide.

I managed to cobble together a script that does that. However, it only works on the root level for folders.

Is there a relatively simple script I can add to dig recursively within subfolders to do basic A->B processes?

Here's the script for reference. Any advise or feedback is appreciated. Thanks for reading! :D

Code: Select all




// Given the a Folder of files, open the files and process them
function OpenFolder() {
var filesOpened = 0;
var fileList = inputFolder.getFiles();
for ( var i = 0; i < fileList.length; i++ ) {
// Make sure all the files in the folder are compatible with PS
if ( fileList[i] instanceof File && ! fileList[i].hidden && ! IsFileOneOfThese( fileList[i], gFilesToSkip )) {

open( fileList[i] );

filesOpened++;

var docRef = app.activeDocument;

// change the color mode to RGB. Important for resizing GIFs with indexed colors, to get better results, and for web imagery in general
docRef.changeMode(ChangeMode.RGB);

// Process all open documents until no documents
// are left open.
while (app.documents.length >=1){

var savedRuler= app.preferences.rulerUnits;
app.preferences.rulerUnits = Units.PIXELS;
var w = app.activeDocument.width;
var h = app.activeDocument.height;
if(w>h) app.activeDocument.resizeCanvas (w, w, AnchorPosition.MIDDLECENTER);
if(w<h) app.activeDocument.resizeCanvas (h, h, AnchorPosition.MIDDLECENTER);
//if w==h already square
app.preferences.rulerUnits = savedRuler;

// these are our values for the end result width and height (in pixels) of our image
var fWidth = 1000;
var fHeight = 1000;
// do the resizing. if height > width (portrait-mode) resize based on height. otherwise, resize based on width
if (docRef.height > docRef.width) {
docRef.resizeImage(null,UnitValue(fHeight,"px"),null,ResampleMethod.BICUBIC);
}
else {
docRef.resizeImage(UnitValue(fWidth,"px"),null,null,ResampleMethod.BICUBIC);
}

// our web export options
var options = new ExportOptionsSaveForWeb();
options.quality = 70;
options.format = SaveDocumentType.JPEG;
options.optimized = true;

var newName = 'web-'+docRef.name+'.jpg';
docRef.exportDocument(File(outputFolder +'/'+newName),ExportType.SAVEFORWEB,options);

// Close without saving
app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);
}
}
}
return filesOpened;
}