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 corresponding to the specified matching portion of the filename would then be applied, overwriting the original files.
I have surrounded each condition in comments clearly identifying each code block so that you can easily copy/paste them to create additional conditions.
You will obviously need to change the name of the action and action set.
This script overwrites the originals, so work on copies.
/*
Batch Play Actions from Conditional Filename Parts.jsx
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 corresponding to 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();
if (!documents.length) {
var savedDisplayDialogs = app.displayDialogs;
var inputFolder = Folder.selectDialog('Select the input folder', '');
var inputFiles = inputFolder.getFiles();
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('-RED') != -1) {
app.doAction('Red Action', 'Change Colour Action Set'); // Change action & action set name
/* CONDITION #1 */
/* CONDITION #2 */
} else if (app.activeDocument.name.indexOf('-GREEN') != -1) {
app.doAction('Green Action', 'Change Colour Action Set'); // Change action & action set name
/* CONDITION #2 */
/* CONDITION #3 */
} else if (app.activeDocument.name.indexOf('-BLUE') != -1) {
app.doAction('Blue Action', 'Change Colour Action Set'); // Change action & action set name
/* CONDITION #3 */
} else {
/* DO SOMETHING ELSE */
}
app.activeDocument.close(SaveOptions.SAVECHANGES);
// Finish doing stuff
} catch (e) {
continue;
}
}
app.displayDialogs = savedDisplayDialogs;
alert('Script completed!' + '\n' + 'Files saved to:' + '\n' + inputFolder.fsName);
} else {
alert('Please close all open files before running this script');
}