Skip to main content
Known Participant
October 2, 2020
Answered

Superscript text font change using script

  • October 2, 2020
  • 2 replies
  • 1536 views

Hi Everyone

Is there script to find and change the font of thesuperscript text.

This topic has been closed for replies.
Correct answer c.pfaffenbichler

The script will indeed be similar to the one referred to by c.pfaffenbichler 

We get a descriptor for the text layer, get an ActionList with a list of styles, loop through all the styles looking for the one in which the 'baseline' key is set to 'superScript'. Then, in this style, change the values ​​of the keys fontName, fontPostScriptName, fontScript, fontStyleName to the required ones (I have never changed the font using a script, so we need to experiment to find out what the minimum set of keys is needed for the font to change correctly - we may have to refer to the list of fonts application to get all the required attributes). After that, collect the descriptor in reverse order and assign it to the text layer.


»fontPostScriptName« and »color« seem to be enough. 

// base on code by jazz-y;
// change font of superscript letters;
// 2020, use it at your own risk;
s2t = stringIDToTypeID;

(r = new ActionReference()).putProperty(s2t('property'), p = s2t('numberOfLayers'));
r.putEnumerated(s2t('document'), s2t('ordinal'), s2t('targetEnum'));
var len = executeActionGet(r).getInteger(p);

for (var i = 0; i <= len; i++) {
    (r = new ActionReference()).putProperty(s2t('property'), p = s2t('textKey'));
    r.putIndex(s2t('layer'), i);
    var theCheck = false;
    if (executeActionGet(r).hasKey(p)) {
        var textKey = executeActionGet(r).getObjectValue(p),
            styleList = textKey.getList(s2t('textStyleRange')),
            l = new ActionList(),
            d = new ActionDescriptor(),
            z = false;
        for (var x = 0; x < styleList.count; x++) {
            k = styleList.getObjectValue(x);
            s = k.getObjectValue(s2t('textStyle'));
            theX = s.getEnumerationValue(stringIDToTypeID("baseline"));
            var theNewOne = new ActionDescriptor;
////////////////////////////////////
            if (theX == "2477") {
                var theCheck = true;
                var theStyle = k.getObjectValue(s2t('textStyle'));
                theStyle.putString(s2t('fontPostScriptName'), "Helvetica-Bold");               
                var d = new ActionDescriptor();
                d.putDouble(s2t('red'), s.getObjectValue(s2t('color')).getInteger(s2t('red')));
                d.putDouble(s2t('grain'), s.getObjectValue(s2t('color')).getInteger(s2t('grain')));
                d.putDouble(s2t('blue'), s.getObjectValue(s2t('color')).getInteger(s2t('blue')));
                theStyle.putObject(s2t('color'), s2t('RGBColor'), d);
                k.putObject(s2t('textStyle'), s2t('textStyle'), theStyle)
            } else {
            };
////////////////////////////////////
            l.putObject(s2t('textStyleRange'), k)
        }
        if (theCheck == true) {
            textKey.putList(s2t('textStyleRange'), l)
            var d = new ActionDescriptor();
            (r = new ActionReference()).putIndex(s2t('layer'), i);
            d.putReference(s2t('null'), r);
            d.putObject(s2t('to'), s2t('textLayer'), textKey);
            executeAction(s2t('set'), d, DialogModes.NO);
        }
    }
};

2 replies

@mj
Community Expert
Community Expert
October 2, 2020

Hi @Ragav@july2020 ,

I don't see how this can be done easily.

Ps has a basic find and replace text function, so some serious scripting will be needed.

To add to @c.pfaffenbichler 's links, here some scripting resources from Adobe.

ADOBE PHOTOSHOP SCRIPTING

Good luck

c.pfaffenbichler
Community Expert
Community Expert
October 2, 2020

As Photoshop is not the primary choice for serious typographical work I doubt it. 

 

Several of the Forum regulars could almost certainly create one fairly easily, though. 

But let me be blunt: Do you just want someone to do your work for you or are you looking for advice? 

 

There was a thread recently that concerned changing type properties via Script; it was about color, but the code might be helpful nonetheless. 

Change a certain color of texts to a new color

Known Participant
October 2, 2020

I need help for work to change the font of the superscript.

Known Participant
October 2, 2020

Is this possible to achieve through unicode of superscript from one font to another.