[Adobe jsx] Dateinamen als Textlayer ausgeben

Photoshop Scripting anyone? Hier ein kurzes Beispiel, wie man alle Dateinamen eines Ordners ausliest und als Textlayer ausgibt.



// Example of Reading all Files in a Folder
// and creating Textlayers from its filenames

// enable double clicking from the Macintosh Finder or the Windows Explorer
#target photoshop

// in case we double clicked the file
app.bringToFront();

// debug level: 0-2 (0:disable, 1:break on error, 2:break at beginning)
// $.level = 0;
// debugger; // launch debugger on next line

var strtRulerUnits = app.preferences.rulerUnits;
var strtTypeUnits = app.preferences.typeUnits;
app.preferences.rulerUnits = Units.PIXELS;
app.preferences.typeUnits = TypeUnits.POINTS;

var docRef = app.documents.add(1280, 720, 72);
var selRef = app.activeDocument.all;

var textColor = new SolidColor();
textColor.rgb.red = 255;
textColor.rgb.green = 0;
textColor.rgb.blue = 0;

// suppress all dialogs
app.displayDialogs = DialogModes.NO;

try {
// Ask user for input folder
var inputFolder = Folder.selectDialog("select Folder");
var fileList = inputFolder.getFiles("*.*");
for (var i = 0; i < fileList.length; i++) { // split example var explodedName = fileList[i].name.split("."); var newText = explodedName[0] +String.fromCharCode(13)+explodedName[1]; var newTextLayer = docRef.artLayers.add(); newTextLayer.kind = LayerKind.TEXT; newTextLayer.textItem.contents = newText; newTextLayer.textItem.position = Array(240, 10+i*36); newTextLayer.textItem.size = 12; newTextLayer.textItem.color = textColor; } } catch (exception) { alert(exception); } finally { app.displayDialogs = startDisplayDialogs; } app.preferences.rulerUnits = strtRulerUnits; app.preferences.typeUnits = strtTypeUnits; docRef = null; textColor = null; newTextLayer = null;

Schreibe einen Kommentar

Deine eMailadresse wird nicht veröffentlicht.