Here is an example of a self-contained script that will save JPEG files with the file name in the lower right from selected input files. A sub-directory will be created titled "Filename Added" to ensure that the original files with the same name are not overwritten.
[CODE=javascript]#target photoshop
// Save the original dialog display
var originalDialogMode = app.displayDialogs;
app.displayDialogs = DialogModes.NO;
// Save the original ruler units
var originalRulerUnits = app.preferences.rulerUnits;
// Set the working units to px
app.preferences.rulerUnits = Units.PIXELS;
var selectFiles = File.openDialog("Select the input files:", Multiselect = true);
var outputFolder = Folder.selectDialog("Select the save folder:");
outputFolder = new Folder(decodeURI(outputFolder) + '/Filename Added');
if (outputFolder.exists == false) outputFolder.create();
// Set the file processing counter to zero
var counter = 0;
for (var i = 0; i < selectFiles.length; i++) {
open(selectFiles[i]);
// Create the text layer
app.activeDocument.artLayers.add();
app.activeDocument.activeLayer.kind = LayerKind.TEXT;
// Optionally set the layer to difference blend mode
//app.activeDocument.activeLayer.blendMode = BlendMode.DIFFERENCE;
// Set the text content to the document name without filename extension
var theText = app.activeDocument.activeLayer.textItem;
theText.contents = app.activeDocument.name.replace(/\.[^\.]+$/, '');
// Set the text variables
theText.position = [85, 140];
var theColour = new SolidColor();
theColour.rgb.red = 255;
theColour.rgb.green = 255;
theColour.rgb.blue = 255;
theText.color = theColour;
//theText.font = 'Times-Italic';
theText.font = 'ArialMT';
//theText.size = 20;
// Set text height to 5% of the doc height
var textSize = app.activeDocument.height / 100 * 5 * 72 / app.activeDocument.resolution;
theText.size = textSize;
// Move the text to the lower right, offset by the text height x2
app.activeDocument.selection.selectAll();
alignToSel('AdRg');
alignToSel('AdBt');
app.activeDocument.activeLayer.translate(-textSize.value * 2, -textSize.value * 2);
app.activeDocument.selection.deselect();
// Save
var saveJPEGName = File(outputFolder + "/" + theText.contents + ".jpg");
saveJPEG(saveJPEGName);
app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);
// Increment the file processing counter
counter++;
}
// Reset the original application settings
app.preferences.rulerUnits = originalRulerUnits;
app.displayDialogs = originalDialogMode;
// End of script notification
alert("Script completed!" + "\r" + "Files selected: " + selectFiles.length + "\r" + "Files processed: " + counter);
// Functions
function alignToSel(method) {
var desc = new ActionDescriptor();
var ref = new ActionReference();
ref.putEnumerated(charIDToTypeID("Lyr "), charIDToTypeID("Ordn"), charIDToTypeID("Trgt"));
desc.putReference(charIDToTypeID("null"), ref);
desc.putEnumerated(charIDToTypeID("Usng"), charIDToTypeID("ADSt"), charIDToTypeID(method));
try {
executeAction(charIDToTypeID("Algn"), desc, DialogModes.NO);
} catch (e) {}
}
function saveJPEG(saveFile) {
var jpgOptns = new JPEGSaveOptions();
jpgOptns.formatOptions = FormatOptions.STANDARDBASELINE;
jpgOptns.embedColorProfile = true;
jpgOptns.quality = 10; // 0 - 12
activeDocument.saveAs(saveFile, jpgOptns, true, Extension.LOWERCASE);
}[/CODE]