What's new
Photoshop Gurus Forum

Welcome to Photoshop Gurus forum. Register a free account today to become a member! It's completely free. Once signed in, you'll enjoy an ad-free experience and be able to participate on this site by adding your own topics and posts, as well as connect with other members through your own private inbox!

Reply to thread

As an example, the following script will add the filename to a single document. One can then record the execution of the script into an action, then use File > Automate > Batch or use the Image Processor or Image Processor Pro or other batch scripts to run the action and save the file to various file formats.


Further code could be added to batch process multiple selected files, or a folder and save to a required file format/options so that there is no need to record the script into an action and use batch.


[CODE=javascript]// 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;


// Create the text layer

app.activeDocument.artLayers.add().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

(theText = app.activeDocument.activeLayer.textItem).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;

//var textSize = app.activeDocument.height / 100 * 5 * 72 / app.activeDocument.resolution;

//theText.size = textSize;


// Move the text to the lower right, offset by 50px

app.activeDocument.selection.selectAll();

alignToSel('AdRg');

alignToSel('AdBt');

app.activeDocument.activeLayer.translate(-50, -50);

app.activeDocument.selection.deselect();


// Reset the original application settings

app.preferences.rulerUnits = originalRulerUnits;

app.displayDialogs = originalDialogMode;



// 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) {}

}[/CODE]



[URL unfurl="true"]https://prepression.blogspot.com/2017/11/downloading-and-installing-adobe-scripts.html[/URL]


What is our favorite program/app? (Hint - it begins and ends with the letter P)
Back
Top