• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Action or Script to replacing fonts in multiple documents

New Here ,
Apr 17, 2020 Apr 17, 2020

Copy link to clipboard

Copied

I am looking for a script that will allow me to replace all the instances of ANY typeface regardless of size or weight to one specific typeface/weight (size should remain the same) across multiple - several hundred - files.

 

I've browsed the boards and seen a few references to something similar, but none of them seem to work in practice for this need.

 

Sarah

TOPICS
Actions and scripting

Views

630

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe
Community Expert ,
Apr 23, 2020 Apr 23, 2020

Copy link to clipboard

Copied

I suppose that would take a Script and not necessarily a simple one at that … how important/frequent is the task for you? 

Have you found any Scripts that approach what you are after? 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 23, 2020 Apr 23, 2020

Copy link to clipboard

Copied

There was something similar … 

https://community.adobe.com/t5/photoshop/how-can-i-randomly-apply-one-of-a-limited-number-of-fonts-t...

 

Try this: 

 

// 2020, use it at your own risk;
if (app.documents.length > 0) {
var myDocument = app.activeDocument;
var theFonts = ["Courier-Bold"];
var theNumberOfFonts = theFonts.length;
var theTypeLayers = collectTypeLayers ();
for (var m = 0; m < theTypeLayers.length; m++) {
changeFont (theFonts[Math.floor (Math.random()*theNumberOfFonts)], theTypeLayers[m][1])
};
};
////// collect type layers //////
function collectTypeLayers () {
// the file;
var myDocument = app.activeDocument;
// get number of layers;
var ref = new ActionReference();
ref.putEnumerated( charIDToTypeID("Dcmn"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") ); 
var applicationDesc = executeActionGet(ref);
var theNumber = applicationDesc.getInteger(stringIDToTypeID("numberOfLayers"));
// process the layers;
var theLayers = new Array;
for (var m = 0; m <= theNumber; m++) {
try {
var ref = new ActionReference();
ref.putIndex( charIDToTypeID( "Lyr " ), m);
var layerDesc = executeActionGet(ref);
var layerSet = typeIDToStringID(layerDesc.getEnumerationValue(stringIDToTypeID("layerSection")));
var isBackground = layerDesc.getBoolean(stringIDToTypeID("background"));
// if not layer group collect values;
if (layerSet != "layerSectionEnd" && layerSet != "layerSectionStart" && isBackground != true && layerDesc.hasKey(stringIDToTypeID("textKey")) == true) {
var theName = layerDesc.getString(stringIDToTypeID('name'));
var theID = layerDesc.getInteger(stringIDToTypeID('layerID'));
theLayers.push([theName, theID])
};
}
catch (e) {};
};
return theLayers
};
////// change font //////
function changeFont (theFont, theID) {
// =======================================================
var idsetd = charIDToTypeID( "setd" );
    var desc2 = new ActionDescriptor();
    var idnull = charIDToTypeID( "null" );
        var ref1 = new ActionReference();
        var idPrpr = charIDToTypeID( "Prpr" );
        var idTxtS = charIDToTypeID( "TxtS" );
        ref1.putProperty( idPrpr, idTxtS );
        ref1.putIdentifier(charIDToTypeID( "TxLr" ), theID);
    desc2.putReference( idnull, ref1 );
    var idT = charIDToTypeID( "T   " );
        var desc3 = new ActionDescriptor();
        var idfontPostScriptName = stringIDToTypeID( "fontPostScriptName" );
        desc3.putString( idfontPostScriptName, theFont );
    desc2.putObject( idT, idTxtS, desc3 );
executeAction( idsetd, desc2, DialogModes.NO );
};
// based on code by mike hale, via paul riggott;
function selectLayerByID(id,add){ 
add = undefined ? add = false:add 
var ref = new ActionReference();
    ref.putIdentifier(charIDToTypeID("Lyr "), id);
    var desc = new ActionDescriptor();
    desc.putReference(charIDToTypeID("null"), ref );
       if(add) desc.putEnumerated( stringIDToTypeID( "selectionModifier" ), stringIDToTypeID( "selectionModifierType" ), stringIDToTypeID( "addToSelection" ) ); 
      desc.putBoolean( charIDToTypeID( "MkVs" ), false ); 
   try{
    executeAction(charIDToTypeID("slct"), desc, DialogModes.NO );
}catch(e){
alert(e.message); 
}
};

 

 

From this 

Screenshot 2020-04-23 at 13.50.21.png

to this

Screenshot 2020-04-23 at 13.54.49.png

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 23, 2020 Apr 23, 2020

Copy link to clipboard

Copied

LATEST

I omitted to mention: You would still need to combine the Script with Batch or Image Processor etc. to process multiple images in one go. 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines