@that35510420xudu
You can try the following 1.2 version, remember to disable or remove the Save/Save As step from all 3 actions as this is now being performed by the script:
/*
Batch Play Actions from Conditional Folder Names v1-2.jsx
v1.0 - 21st February 2024, Stephen Marsh
v1.1 - 23rd February 2024, Replaced the original sub-folder/file processing code as it had unexpected errors in Windows (it worked on the Mac without issue)
v1.2 - 24th February 2024, Added a save to JPEG in a folder
https://community.adobe.com/t5/photoshop-ecosystem-discussions/ps-script-for-multiple-actions-for-files-in-different-folders-automatic/m-p/14435721
NOTE:
* There must be 3 folders named: folder1, folder2, folder3
* The action set must be named: photo adjust
* There must be 3 actions named: action1, action2, action3
*/
#target photoshop
try {
// Main script function
(function () {
// Save and disable dialogs
var restoreDialogMode = app.displayDialogs;
app.displayDialogs = DialogModes.NO;
// Recursive open files from 1st level sub-folders under the selected parent/root folder by c.pfaffenbichler (2022)
var theFolder = Folder.selectDialog('Please select the input folder:');
if (theFolder === null) return;
var theFolders = theFolder.getFiles(isFolder);
//theFolders.sort().reverse();
theFolders.sort();
for (var m = 0; m < theFolders.length; m++) {
var inputFolder = theFolders[m];
cTID = function (s) {
return app.charIDToTypeID(s);
};
sTID = function (s) {
return app.stringIDToTypeID(s);
};
var inputFiles = inputFolder.getFiles(/\.(jpg|jpeg|tif|tiff|png|psd|psb|gif|webp)$/i);
// inputFiles.sort().reverse();
inputFiles.sort();
// Validate that the file list is not empty
var inputCount = inputFiles.length;
var cancelScript = (inputCount === 0);
if (cancelScript === true) {
alert('Zero input files found, script cancelled!');
return;
}
// Hide the Photoshop panels
app.togglePalettes();
for (var i = 0; i < inputFiles.length; i++) {
app.open(File(inputFiles[i]));
// Conditionally play the actions corresponding to the folder name
try {
if (/folder1$/i.test(app.activeDocument.path.fsName)) {
app.doAction('action1', 'photo adjust');
saveJPG();
} else if (/folder2$/i.test(app.activeDocument.path.fsName)) {
app.doAction('action2', 'photo adjust');
saveJPG();
} else if (/folder3$/i.test(app.activeDocument.path.fsName)) {
app.doAction('action3', 'photo adjust');
saveJPG();
} else {
alert('The idea is not to see this message...');
app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);
}
} catch (e) {
alert('ERROR: Check that the action exists and is named correctly!');
}
app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);
}
}
// Restore saved dialogs and panels
app.displayDialogs = restoreDialogMode;
app.togglePalettes();
// End of script notification
app.beep();
alert('Script completed!');
function isFolder(theFile) {
if (theFile.constructor.name == "Folder") {
return true;
} else {
return false;
}
}
function saveJPG() {
var docPath = app.activeDocument.path;
var jpgFolder = new Folder(docPath + '/JPG/');
if (!jpgFolder.exists) {
jpgFolder.create();
}
var docName = app.activeDocument.name.replace(/\.[^\.]+$/, '');
var jpgSave = new File(jpgFolder + "/" + docName + ".jpg");
var jpgOptns = new JPEGSaveOptions();
jpgOptns.formatOptions = FormatOptions.STANDARDBASELINE;
jpgOptns.embedColorProfile = true;
jpgOptns.matte = MatteType.NONE;
jpgOptns.quality = 12;
app.activeDocument.saveAs(jpgSave, jpgOptns, true, Extension.LOWERCASE);
}
}());
} catch (e) {
// Restore saved dialogs
app.displayDialogs = restoreDialogMode;
alert('Oops... Something went wrong!' + '\r' + e + ' ' + e.line);
}