Batch Play Actions from Conditional Filename Parts + New Feature
Hello there!
I'm hoping that someone can help me complete the script provided below. I found it in another discussion here and am having a bit of trouble trying to add a new feature to it.
I need it to duplicate any PSD file that ends with -3, retain its name, and be added to this action queue.
Explanation:
We have product photos that need to be ran through some actions in order to format them for our needs. We only take a photograph of 1 side of the product & manually go in to create a duplicate, rename it, and then run it through an action as well. This block of code seems to fit what we need ALMOST perfectly, but I'm not sure how to fit in the tedious bit where we duplicate the file that ends with "-3.psd" while allowing it to retain its name before the suffix & then be ran through its own droplet to flip the photo and change the suffix to "-2.psd". The possibility of this being done to the "-3.jpg" after the fact is fine too, I just need the final product to end with a new "-2.jpg" file that is a horizontally flipped version of the original "-3" view.
/*
Batch Play Actions from Conditional Filename Parts - Prompt for Suffix and JPEG Save Location.jsx
Changelog:
2nd May 2020 - Initial Release
3rd May 2020 - Added interactive JPEG save & suffix prompts
https://community.adobe.com/t5/photoshop/script-to-place-logos-in-diffrent-phones-cases-in-photshop/m-p/11098559
Script to place Logos in diffrent phones cases in Photshop
The following code example presumes that a folder of input files have a hyphen - delimiter with variable case-sensitive text, such as a colour name:
myfile-RED.psd
myfile-GREEN.psd
myfile-BLUE.psd
An action matching the specified matching portion of the filename would then be applied, overwriting the original files.
The indexOf method is case sensitive:
if (app.activeDocument.name.indexOf('-RED') != -1) {
An alternative is to use a case insensitive regular expression based match:
if (app.activeDocument.name.match(/-Red/gi) != null) {
*/
#target photoshop
app.bringToFront();
(function () {
if (!documents.length) {
var savedDisplayDialogs = app.displayDialogs;
var inputFolder = Folder.selectDialog('Select the input folder:', ''); // Optionally add a default directory
if (inputFolder == null) {
return
}; // Test if cancel returns null, then do nothing.
var outputFolder = Folder.selectDialog('Select the JPEG output folder:', ''); // Optionally add a default directory
if (outputFolder == null) {
return
}; // Test if cancel returns null, then do nothing.
var inputFiles = inputFolder.getFiles(/\.(jpg|jpeg|tif|tiff|psd|psb|eps|png|bmp|gif)$/i); // Add or remove as required
app.displayDialogs = DialogModes.NO;
for (var a = 0; a < inputFiles.length; a++) {
try {
var inDoc = open(inputFiles[a]);
// START DOING STUFF
/* CONDITION #1 */
if (app.activeDocument.name.indexOf('-0') != -1) {
app.doAction('Default View', 'View Set'); // Change action & action set name
/* CONDITION #1 */
/* CONDITION #2 */
} else if (app.activeDocument.name.indexOf('-1') != -1) {
app.doAction('Default View', 'View Script'); // Change action & action set name
/* CONDITION #2 */
/* CONDITION #3 */
} else if (app.activeDocument.name.indexOf('-3') != -1) {
app.doAction('Tilt View 3', 'View Script'); // Change action & action set name
/* CONDITION #3 */
/* CONDITION #4 */
} else if (app.activeDocument.name.indexOf('-4') != -1) {
app.doAction('Default View', 'View Script'); // Change action & action set name
/* CONDITION #4 */
} else {
/* DO SOMETHING ELSE */
}
var docName = app.activeDocument.name.replace(/\.[^\.]+$/, '');
/* var saveFileJPEG = new File(outputFolder + '/' + docName + '_' + suffixCleansed + '.jpg');
SaveForWeb(saveFileJPEG); */
var doc = app.activeDocument;
var jpgOptions = new JPEGSaveOptions();
jpgOptions.quality = 12;
jpgOptions.embedColorProfile = true;
jpgOptions.formatOptions = FormatOptions.PROGRESSIVE;
jpgOptions.scans = 5;
jpgOptions.matte = MatteType.NONE;
doc.saveAs (new File(outputFolder + '/' + fileName + '.jpg'), jpgOptions);
app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);
// FINISH DOING STUFF
} catch (e) {
continue;
}
}
app.displayDialogs = savedDisplayDialogs;
alert('Script completed!' + '\n' + inputFiles.length + ' files saved to:' + '\n' + outputFolder.fsName);
} else {
alert('Please close all open files before running this script');
}
})();
