Copy link to clipboard
Copied
Hi,
I'm looking for a custom keyboard shortcut that will change my selected text within a layer to a specific font within the same font family. I do not want to change the font of the whole layer.
Currently, I have to go back and forth with mouse & keyboard and am looking for a quick way to avoid this and do all with keyboard.
See screenshots below.
Thanks.
Copy link to clipboard
Copied
To be blunt:
While this may be possible via Scripting (with some workaround to determine the selected range) I would recommend doing type-heavy work in more appropriate software (Indesign, Illustrator, … for example).
Copy link to clipboard
Copied
Copy link to clipboard
Copied
This is a demo that splits your text layer at the return character and formats just one piece. I use this basic process in numerous text processing scripts. Sorry for the lack of comments, again this is just a framework.
#target photoshop
layerUpdate();
function setFormatting(start, end, fontName, fontStyle, fontSize){
var idsetd = app.charIDToTypeID('setd');
var action = new ActionDescriptor();
var idnull = app.charIDToTypeID('null');
var reference = new ActionReference();
var idTxLr = app.charIDToTypeID('TxLr');
var idOrdn = app.charIDToTypeID('Ordn');
var idTrgt = app.charIDToTypeID('Trgt');
reference.putEnumerated(idTxLr, idOrdn, idTrgt);
action.putReference(idnull, reference);
var idT = app.charIDToTypeID('T ');
var textAction = new ActionDescriptor();
var idTxtt = app.charIDToTypeID('Txtt');
var actionList = new ActionList();
var textRange = new ActionDescriptor();
var idFrom = app.charIDToTypeID('From');
textRange.putInteger(idFrom, start);
textRange.putInteger(idT, end);
var idTxtS = app.charIDToTypeID('TxtS');
var formatting = new ActionDescriptor();
var idFntN = app.charIDToTypeID('FntN');
formatting.putString(idFntN, fontName);
var idFntS = app.charIDToTypeID('FntS');
formatting.putString(idFntS, fontStyle);
var idSz = app.charIDToTypeID('Sz ');
var idPnt = app.charIDToTypeID('#Pnt');
formatting.putUnitDouble(idSz, idPnt, fontSize);
textRange.putObject(idTxtS, idTxtS, formatting);
actionList.putObject(idTxtt, textRange);
textAction.putList(idTxtt, actionList);
action.putObject(idT, idTxLr, textAction);
app.executeAction(idsetd, action, DialogModes.NO);
}
function layerUpdate(){
if(documents.length > 0){
//declare demo variables
var text1 = "test";
var text2 = "test replacement";
var oldtSize = 48;
var tSize = 24;
var tFont = "Calibri";
var tStyle = "bold";
var tLead = 24;
var boxH = 200;
var boxW = 400;
var tColor = new SolidColor;
tColor.rgb.hexValue = "FF0000";
//end demo variables
var originalDialogMode = app.displayDialogs;
app.displayDialogs = DialogModes.ERROR;
var originalRulerUnits = preferences.rulerUnits;
var j = 0;
try{
var docRef = activeDocument;
preferences.rulerUnits = Units.POINTS;
var m = 0;
for(var i = 0; i < docRef.artLayers.length; i++){
var LayerRef = docRef.artLayers[i];
if(LayerRef.kind == LayerKind.TEXT){
var TextRef = LayerRef.textItem;
TextRef.textComposer = TextComposer.ADOBESINGLELINE;
var layerText = TextRef.contents;
var newText = layerText.replace(text1, text2);
if(newText != layerText){
j = i;
TextRef.contents = newText;
if(TextRef.size == oldtSize){
TextRef.size = tSize;
TextRef.font = tFont;
TextRef.useAutoLeading = false;
TextRef.leading = tLead;
TextRef.color = tColor;
var l = TextRef.contents.split(/\r/);
docRef.activeLayer = LayerRef;
setFormatting(0, l[0].length, tFont, tStyle, oldtSize);
preferences.rulerUnits = Units.PIXELS;
if(TextRef.kind == TextType.PARAGRAPHTEXT){
TextRef.height = boxH;
TextRef.width = boxW;
}
preferences.rulerUnits = Units.POINTS;
break;
}
}
}
}
}
catch(e){
alert(e + ' ' + e.line);
preferences.rulerUnits = originalRulerUnits;
app.displayDialogs = originalDialogMode;
return;
}
preferences.rulerUnits = originalRulerUnits;
app.displayDialogs = originalDialogMode;
}
else{
alert('You must have a document open to run this script.');
return;
}
}