Skip to main content
Participant
April 23, 2025
Question

Applying a font to a text layer using a script - PS 2025 OSX

  • April 23, 2025
  • 2 replies
  • 181 views

Hi has anyone got a code snippet that reliably applies a different font to a text layer? I been trying to change variations of Noto Sans fonts (depending on to local language). I have a lookup table for language vs font, but I cannot seem to get the new font applied to a named layer! Any help or ideas?

2 replies

Stephen Marsh
Community Expert
Community Expert
April 23, 2025

If I remember correctly, scripting fonts can sometimes be tricky, do you only wish to change the existing font but no other attributes should be changed, such as size, colour, etc.?

 

One example:

 

https://www.mightyplugins.cc/magic-scripts

Advanced font remapping 1.0

 

P.S. If you search the forum, you should be able to find many examples.

Legend
April 23, 2025

This is a basic example of setting text properties.

 

layerUpdate();

function layerUpdate(){
    if(documents.length > 0){
        var originalDialogMode = app.displayDialogs;
        app.displayDialogs = DialogModes.ERROR;
        var originalRulerUnits = preferences.rulerUnits;
        try{
            var docRef = activeDocument;
            preferences.rulerUnits = Units.POINTS;
            for(var i = 0; i < docRef.artLayers.length; i++){
                var LayerRef = docRef.artLayers[i];
                if(LayerRef.kind == LayerKind.TEXT){
                    var TextRef = LayerRef.textItem;
                    TextRef.size = 32;
                    TextRef.useAutoLeading = false;
                    TextRef.leading = 32;
                    TextRef.font = 'Calibri';
                    TextRef.justification = Justification.CENTER;
                    TextRef.autoKerning = AutoKernType.METRICS;
                    }
                }
            preferences.rulerUnits = originalRulerUnits;
            app.displayDialogs = originalDialogMode;
            }
        catch(e){
            }
        }
    }