📜 ⬆️ ⬇️

Scripts in Photoshop

There is such a little-studied functionality of designers in Photoshop as scripts.
Many use Actions, but for writing real jsx scripts you need at least basic knowledge of JS, VBS or AppleScript.

Imagine such a task as creating 50 unique graphic titles for a site, a general outline, color, size, but, alas, with different content.


How to solve the problem?
1) Sit down and pens up 50 titles by copying text from a text file, adjusting the size and saving files.
2) Create a script :)

')
I quote the source code of the script below (a convenient ExtendScript Toolbox is supplied for editing with Photoshop):

#target photoshop
app.bringToFront();
var strtRulerUnits = app.preferences.rulerUnits;
var strtTypeUnits = app.preferences.typeUnits;
app.preferences.rulerUnits = Units.INCHES;
app.preferences.typeUnits = TypeUnits.POINTS;
var docRef = app.documents.add(7, 5, 72);
app.displayDialogs = DialogModes.NO;
var textColor = new SolidColor;
textColor.rgb.red = 255;
textColor.rgb.green = 0;
textColor.rgb.blue = 0;
var myFile = File('/c/script/text.txt');
if (myFile.exists == true){
myFile.open('r', undefined, undefined)
var line;
while(!myFile.eof)
{
line = myFile.readln();
createText(line);
}
myFile.close();
} else {
new File(myFile);
}
function createText(text){
var newTextLayer = docRef.artLayers.add();
newTextLayer.kind = LayerKind.TEXT;
newTextLayer.textItem.contents = text;
newTextLayer.textItem.position = Array(0.75, 0.75);
newTextLayer.textItem.size = 36;
newTextLayer.textItem.font = "Verdana";
newTextLayer.textItem.color = textColor;
}
app.preferences.rulerUnits = strtRulerUnits;
app.preferences.typeUnits = strtTypeUnits;
docRef = null;
textColor = null;
newTextLayer = null;


What the script does:
Line by line reads the file text.txt and for each line creates a separate text layer in the file containing the value of the line


We save it with the .jsx extension, we create C: /script/text.txt and hurray, a lot has been simplified :)

Source: https://habr.com/ru/post/41020/


All Articles