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

Selecting a text layer in a particular artboard by Artboard size using Java script?

Participant ,
Oct 02, 2022 Oct 02, 2022

Copy link to clipboard

Copied

I want to select all the text layers by font type in a particular Artboard. Artboard needs to be identified by its dimension. 
I have a script to select all the artboards in an active document. Could anyone help me modify this? 

var activeDoc = app.activeDocument;

var artboards = activeDoc.layers;

var visibleArtboards = [];
for (var i = 0; i < artboards.length; i++) {
    if (artboards[i].visible) {

        // select ID as we go along
        var layerID = artboards[i].id;
        visibleArtboards.push(layerID);

    }
}

// Loop over the layers again and select all the art boards
for (var i = 0; i < visibleArtboards.length; i++) {
    // add to current selection of layers
    select_by_ID(visibleArtboards[i], true);
}

function select_by_ID(id, add) {
    if (add == undefined) add = false;
    var desc1 = new ActionDescriptor();
    var ref1 = new ActionReference();
    ref1.putIdentifier(charIDToTypeID('Lyr '), id);
    desc1.putReference(charIDToTypeID('null'), ref1);
    if (add) desc1.putEnumerated(stringIDToTypeID("selectionModifier"), stringIDToTypeID("selectionModifierType"), stringIDToTypeID("addToSelection"));
    executeAction(charIDToTypeID('slct'), desc1, DialogModes.NO);
} // end of selectByID()

 

TOPICS
Actions and scripting

Views

803

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

correct answers 3 Correct answers

Community Expert , Oct 06, 2022 Oct 06, 2022

This script should keep the layers visibility the same.

#target photoshop

var doc = app.activeDocument;
var oldPref = app.preferences.rulerUnits;
app.preferences.rulerUnits = Units.PIXELS;

var ab, aLayer, aW, aH

var defaultValue = '';
var desktopHead = prompt("Paste your new headline", defaultValue);

var docLayers = doc.layers.length; //getting top layers because artboards are top layers

for(var i=0;i<docLayers;i++){
    aLayer = doc.layers[i];
    ab = artboard_rectangle(aLayer);
    aW = 
...

Votes

Translate

Translate
Community Expert , Oct 23, 2022 Oct 23, 2022

Here's the script to change "discount" to another color. I don't know about changing the 1 to super script. I would need the code for that as well.

 

#target photoshop
var testText = 'no no'
var doc = app.activeDocument;
var oldPref = app.preferences.rulerUnits;
app.preferences.rulerUnits = Units.PIXELS;

var ab, aLayer, aW, aH

var defaultValue = '';
var desktopHead = prompt("Paste your new headline", defaultValue);

var docLayers = doc.layers.length; //getting top layers because artboards are 
...

Votes

Translate

Translate
Community Expert , Oct 24, 2022 Oct 24, 2022

Okay, I think I have the script you want. Thanks to @r-bin and @pixxxelschubser for the code to change the color and superscript of text items.

 

#target photoshop
// some code written by r-bin
// other code adapted for actuel requirements by pixxxelschubser
// final code by Chuck Uebele

var doc = app.activeDocument;
var oldPref = app.preferences.rulerUnits;
app.preferences.rulerUnits = Units.PIXELS;
var useSuperscript = false;

var ab, aLayer, aW, aH

var defaultValue = '';
var desktopHead = p
...

Votes

Translate

Translate
Adobe
Community Expert ,
Oct 02, 2022 Oct 02, 2022

Copy link to clipboard

Copied

Your script seems to select more that just artboards, so it needs some refinement. Here's a script by r-bin (slightly modified) that will displace the artboard size. So this script needs to be incorporated into your script to find the artboard the size you want it. Then you need to loop through the correct artboard, find the text layers, and the see if it's the text font that you want.

 

var layer = activeDocument.layers[0];
var lb = layer_bounds(layer);
var ab = artboard_rectangle(layer);
alert("DOM width = " + (activeDocument.activeLayer.bounds[2]-activeDocument.activeLayer.bounds[0]) + "\n\n"+
      "AM layer width in px = " + (lb[2]-lb[0]) + "\n\n"+
      "AM artboardr width in px = " + (ab[2]-ab[0]) + '\n\n' +
      'AM artboard height in px = ' +(ab[3]-ab[1]));

/////////////////////////////////////////////////////////////////////////////////

function layer_bounds(layer, no_effects)
    {
    try {        
        var prop = stringIDToTypeID("bounds");
        if (no_effects == true)  prop = stringIDToTypeID("boundsNoEffects");
        if (no_effects == false) prop = stringIDToTypeID("boundsNoMask");
        var r = new ActionReference();    
        r.putProperty(stringIDToTypeID("property"), prop);
        if (layer) r.putIdentifier(stringIDToTypeID("layer"), layer.id);
        else       r.putEnumerated(stringIDToTypeID("layer"), stringIDToTypeID("ordinal"), stringIDToTypeID("targetEnum"));   

        var d = executeActionGet(r).getObjectValue(prop);

        var bounds = new Array();

        bounds[0] = d.getUnitDoubleValue(stringIDToTypeID("left"));
        bounds[1] = d.getUnitDoubleValue(stringIDToTypeID("top")); 
        bounds[2] = d.getUnitDoubleValue(stringIDToTypeID("right"));
        bounds[3] = d.getUnitDoubleValue(stringIDToTypeID("bottom"));

        return bounds;
        }
    catch(e) { alert(e); }
    }

/////////////////////////////////////////////////////////////////////////////////

function artboard_rectangle(layer)
    {
    try {        
        var r    = new ActionReference();    
        r.putProperty(stringIDToTypeID("property"), stringIDToTypeID("artboard"));
        if (layer) r.putIdentifier(stringIDToTypeID("layer"), layer.id);
        else       r.putEnumerated(stringIDToTypeID("layer"), stringIDToTypeID("ordinal"), stringIDToTypeID("targetEnum"));
        var d = executeActionGet(r).getObjectValue(stringIDToTypeID("artboard")).getObjectValue(stringIDToTypeID("artboardRect"));
        var bounds = new Array();
        bounds[0] = d.getUnitDoubleValue(stringIDToTypeID("left"));
        bounds[1] = d.getUnitDoubleValue(stringIDToTypeID("top")); 
        bounds[2] = d.getUnitDoubleValue(stringIDToTypeID("right"));
        bounds[3] = d.getUnitDoubleValue(stringIDToTypeID("bottom"));                                

        return bounds;
        }
    catch(e) { alert(e); }
    }

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
Participant ,
Oct 03, 2022 Oct 03, 2022

Copy link to clipboard

Copied

Thank you so much, Chuck. I will check and get back. I have also added a new script to this post. Could you please check that as well? 

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 ,
Oct 03, 2022 Oct 03, 2022

Copy link to clipboard

Copied

I'm working on it. Might take a bit, as I've run into a snag. Hopefully by this evening. 

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
Engaged ,
Oct 02, 2022 Oct 02, 2022

Copy link to clipboard

Copied

Forgive me. I'm not sure what you mean by "select all the text layers by font type" and "Artboard needs to be identified by its dimension".

 

Do you want to create an array of all the text layers and sort them by font type? Do you want to rename the ArtBoards with the dimensions? Can you give an example of the output you're looking for?

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
Participant ,
Oct 03, 2022 Oct 03, 2022

Copy link to clipboard

Copied

Hey Jugenjury, Thanks for pitching in. I will make sure to put it clear this time. 

I have 10 artboards in a single PSD file. Each artboard is different in size. I would like to access X number of artboards in terms of dimensions and change the text layers content(which are in Arial-bold) within those selected artboards. One single text content to replace all the text layers(which are in Arial-bold) across the selected artboards. Thanks in advance. I hope this is not confusing. 

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
Participant ,
Oct 03, 2022 Oct 03, 2022

Copy link to clipboard

Copied

var fileRef = app.activeDocument;

// Gets user input
var defaultValue = '';
var desktopHead = prompt("Paste your new headline", defaultValue);
layers = fileRef.layers; //getting top layers because artboards are top layers

function changeTextLayerContent(doc, newTextString) {
for (var i = 0, max = doc.layers.length; i < max; i++) {
var layerRef = doc.layers[i];
 
if (layerRef.typename === "ArtLayer") {

if (layerRef.kind === LayerKind.TEXT) {
if (layerRef.textItem.font === "Arial-Bold") {
layerRef.textItem.contents = desktopHead;
}
}
} else {
changeTextLayerContent(layerRef, desktopHead);
}
}
}
changeTextLayerContent(fileRef, desktopHead);


This script will access all the artboard's text layers. But I would like to access only selective artboard's text layers using the artboard's dimensions. 

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 ,
Oct 03, 2022 Oct 03, 2022

Copy link to clipboard

Copied

Okay, try this. You need to know the artboard size to put into the UI. You also need to have the correct name for the font. I had to change your Arial-Bold to Arial-BoldMT.

 

#target photoshop

var doc = app.activeDocument;

var aWidth = 0
var aHeight = 0
var desktopHead = '';
var ab

var dlg = new Window('dialog','Replace Headline');
    dlg.textGP = dlg.add('group');
        dlg.textGP.orientation = 'row';
        dlg.textGP.alignment = ['right','top'];
        dlg.textGP.alignChildren = ['right','top'];
        dlg.textGP.sTxt = dlg.textGP.add('statictext',undefined,'Paste your new headline')
        dlg.textGP.eTxt = dlg.textGP.add('edittext',undefined,'')
            dlg.textGP.eTxt.size = [500,21];    
    dlg.widthGP = dlg.add('group');
        dlg.widthGP.orientation = 'row';
        dlg.widthGP.alignment = ['right','top'];
        dlg.widthGP.alignChildren = ['right','top'];
        dlg.widthGP.sTxt = dlg.widthGP.add('statictext',undefined,'Enter width of artboard')
        dlg.widthGP.eTxt = dlg.widthGP.add('edittext',undefined,'')
            dlg.widthGP.eTxt.size = [500,21];              
    dlg.heightGP = dlg.add('group');
        dlg.heightGP.orientation = 'row';
        dlg.heightGP.alignment = ['right','top'];
        dlg.heightGP.alignChildren = ['right','top'];
        dlg.heightGP.sTxt = dlg.heightGP.add('statictext',undefined,'Enter width of artboard')
        dlg.heightGP.eTxt = dlg.heightGP.add('edittext',undefined,'')
            dlg.heightGP.eTxt.size = [500,21];      
    dlg.btnGp = dlg.add('group');
        dlg.btnGp.orientation = 'row';
        dlg.btnGp.ok = dlg.btnGp.add('button',undefined,'Okay');
        dlg.btnGp.cancel = dlg.btnGp.add('button',undefined,'Cancel');
        
   dlg.btnGp.ok.onClick = function(){

       dlg.close();
       aWidth = Number(dlg.widthGP.eTxt.text);
       aHeight = Number(dlg.heightGP.eTxt.text);
       desktopHead = dlg.textGP.eTxt.text;
       }
            
     dlg.show();

var docLayers = doc.layers.length; //getting top layers because artboards are top layers

for(var i=0;i<docLayers;i++){
    doc.activeLayer = doc.layers[i];
    var aLayer = doc.activeLayer
    ab = artboard_rectangle(doc.activeLayer);
    if((ab[2]-ab[0]) == aWidth && (ab[3]-ab[1]) == aHeight)
        var layLen = aLayer.layers.length
        for(var j=0;j<layLen;j++){
            doc.activeLayer = aLayer.layers[j];
            var layerRef = doc.activeLayer

            if (layerRef.kind === LayerKind.TEXT) {
                if(layerRef.textItem.font === "Arial-BoldMT"){//make sure you have correct font name
                    layerRef.textItem.contents = desktopHead;
                    }
                }
            }
    }

function artboard_rectangle(layer)
    {
    try {        
        var r    = new ActionReference();    
        r.putProperty(stringIDToTypeID("property"), stringIDToTypeID("artboard"));
        if (layer) r.putIdentifier(stringIDToTypeID("layer"), layer.id);
        else       r.putEnumerated(stringIDToTypeID("layer"), stringIDToTypeID("ordinal"), stringIDToTypeID("targetEnum"));
        var d = executeActionGet(r).getObjectValue(stringIDToTypeID("artboard")).getObjectValue(stringIDToTypeID("artboardRect"));
        var bounds = new Array();
        bounds[0] = d.getUnitDoubleValue(stringIDToTypeID("left"));
        bounds[1] = d.getUnitDoubleValue(stringIDToTypeID("top")); 
        bounds[2] = d.getUnitDoubleValue(stringIDToTypeID("right"));
        bounds[3] = d.getUnitDoubleValue(stringIDToTypeID("bottom"));                                

        return bounds;
        }
    catch(e) { alert(e); }
    }

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
Participant ,
Oct 03, 2022 Oct 03, 2022

Copy link to clipboard

Copied

This is awesome, Chuck. It works as expected. But there's a challenge in this script. Whenever the text layer is inside a group, the script doesn't work or gives an error. Is there a fix to it? Please let me know. I really appreciate your support.  

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 ,
Oct 03, 2022 Oct 03, 2022

Copy link to clipboard

Copied

Yea, I can look at that. So the text layer you want to change is within a group, inside the artboard?

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
Participant ,
Oct 03, 2022 Oct 03, 2022

Copy link to clipboard

Copied

Yes, that's right, Chuck. Few text layers might be within the group inside the artboard. Also, the dimensions of the artboards can be called inside the script itself (1000x1000, 400x500, etc). It need not be on the dialog box. If that's not too much of an effort. Thanks in Advance. 

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 ,
Oct 03, 2022 Oct 03, 2022

Copy link to clipboard

Copied

I wasn't sure about the dimensions. You can hard code that into the default for the UI, so that it comes up automatically, but you can then change it easily, if you want. 

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
Participant ,
Oct 03, 2022 Oct 03, 2022

Copy link to clipboard

Copied

Ya, I get it. But I would like to input multiple artboard dimensions. So I was wondering about a way to do that in the script.

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 ,
Oct 03, 2022 Oct 03, 2022

Copy link to clipboard

Copied

You could do that. Just make some arrays to hold the width and height of the various dimensions, and then in tje if statement that checks for the matching sizes, you can enter an or operator to include all the sizes, or just hard code the sizes directly into the if statement. 

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
Participant ,
Oct 03, 2022 Oct 03, 2022

Copy link to clipboard

Copied

Ya sure, Chuck. I will do that. Could you please help me with the below challenge as discussed earlier? 
Whenever the text layer is inside a group, the script doesn't work or gives an error. Is there a way to fix it? Please let me know.

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 ,
Oct 03, 2022 Oct 03, 2022

Copy link to clipboard

Copied

Yea, I'll try and work on it later, today. 

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 ,
Oct 03, 2022 Oct 03, 2022

Copy link to clipboard

Copied

One more time. This will change the text layer within a group. To add more sizes, you have to add them to the if statement that is commented about adding sizes. The different size should be separated by the double pipe symbol ||, which stands for "or". The different sizes should be set in parentheses.

 

#target photoshop

var doc = app.activeDocument;
var oldPref = app.preferences.rulerUnits;
app.preferences.rulerUnits = Units.PIXELS;

var ab, aLayer

var defaultValue = '';
var desktopHead = prompt("Paste your new headline", defaultValue);

var docLayers = doc.layers.length; //getting top layers because artboards are top layers

for(var i=0;i<docLayers;i++){
    doc.activeLayer = doc.layers[i];
    aLayer = doc.activeLayer
    ab = artboard_rectangle(doc.activeLayer);
    if(((ab[2]-ab[0]) == 1000 && (ab[3]-ab[1]) == 1000) || ((ab[2]-ab[0]) == 400 && (ab[3]-ab[1]) == 500)){//add more sizes here
            findTextLayer (aLayer)
            }//end if for artboard size
    }//end for loop

app.preferences.rulerUnits = oldPref;

function findTextLayer(pLayer){
    var layLen = pLayer.layers.length;
    for(var j = 0;j<layLen;j++){
        doc.activeLayer = pLayer.layers[j];
        var layerRef = doc.activeLayer
        if(pLayer.layers[j].typename == 'LayerSet'){
            findTextLayer (pLayer.layers[j]);           
            }//end if for finding layerset
        else{
            if (layerRef.kind === LayerKind.TEXT) {
                if(layerRef.textItem.font === "Arial-BoldMT"){//make sure you have correct font name
                    layerRef.textItem.contents = desktopHead;
                    }//end if for text font
                }//end if for layerkind text            
            }//end else
        };//end for loop
    
    };//end function

function artboard_rectangle(layer)
    {
    try {        
        var r    = new ActionReference();    
        r.putProperty(stringIDToTypeID("property"), stringIDToTypeID("artboard"));
        if (layer) r.putIdentifier(stringIDToTypeID("layer"), layer.id);
        else       r.putEnumerated(stringIDToTypeID("layer"), stringIDToTypeID("ordinal"), stringIDToTypeID("targetEnum"));
        var d = executeActionGet(r).getObjectValue(stringIDToTypeID("artboard")).getObjectValue(stringIDToTypeID("artboardRect"));
        var bounds = new Array();
        bounds[0] = d.getUnitDoubleValue(stringIDToTypeID("left"));
        bounds[1] = d.getUnitDoubleValue(stringIDToTypeID("top")); 
        bounds[2] = d.getUnitDoubleValue(stringIDToTypeID("right"));
        bounds[3] = d.getUnitDoubleValue(stringIDToTypeID("bottom"));                                

        return bounds;
        }
    catch(e) { alert(e); }
    }

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 ,
Oct 03, 2022 Oct 03, 2022

Copy link to clipboard

Copied

I made a slight change to the script. I put the artboard dimensions into single variables, so that the if statement, listing the sizes, isn't so long and will be easier to add more sizes.

#target photoshop

var doc = app.activeDocument;
var oldPref = app.preferences.rulerUnits;
app.preferences.rulerUnits = Units.PIXELS;

var ab, aLayer, aW, aH

var defaultValue = '';
var desktopHead = prompt("Paste your new headline", defaultValue);

var docLayers = doc.layers.length; //getting top layers because artboards are top layers

for(var i=0;i<docLayers;i++){
    doc.activeLayer = doc.layers[i];
    aLayer = doc.activeLayer
    ab = artboard_rectangle(doc.activeLayer);
    aW = ab[2]-ab[0];
    aH = ab[3]-ab[1];
    if((aW == 1000 && aH == 1000) || (aW == 400 && aH == 500)){//add more sizes here
            findTextLayer (aLayer)
            }//end if for artboard size
    }//end for loop

app.preferences.rulerUnits = oldPref;

function findTextLayer(pLayer){
    var layLen = pLayer.layers.length;
    for(var j = 0;j<layLen;j++){
        doc.activeLayer = pLayer.layers[j];
        var layerRef = doc.activeLayer
        if(pLayer.layers[j].typename == 'LayerSet'){
            findTextLayer (pLayer.layers[j]);           
            }//end if for finding layerset
        else{
            if (layerRef.kind === LayerKind.TEXT) {
                if(layerRef.textItem.font === "Arial-BoldMT"){//make sure you have correct font name
                    layerRef.textItem.contents = desktopHead;
                    }//end if for text font
                }//end if for layerkind text            
            }//end else
        };//end for loop
    
    };//end function

function artboard_rectangle(layer)
    {
    try {        
        var r    = new ActionReference();    
        r.putProperty(stringIDToTypeID("property"), stringIDToTypeID("artboard"));
        if (layer) r.putIdentifier(stringIDToTypeID("layer"), layer.id);
        else       r.putEnumerated(stringIDToTypeID("layer"), stringIDToTypeID("ordinal"), stringIDToTypeID("targetEnum"));
        var d = executeActionGet(r).getObjectValue(stringIDToTypeID("artboard")).getObjectValue(stringIDToTypeID("artboardRect"));
        var bounds = new Array();
        bounds[0] = d.getUnitDoubleValue(stringIDToTypeID("left"));
        bounds[1] = d.getUnitDoubleValue(stringIDToTypeID("top")); 
        bounds[2] = d.getUnitDoubleValue(stringIDToTypeID("right"));
        bounds[3] = d.getUnitDoubleValue(stringIDToTypeID("bottom"));                                

        return bounds;
        }
    catch(e) { alert(e); }
    }

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
Participant ,
Oct 05, 2022 Oct 05, 2022

Copy link to clipboard

Copied

This is awesome Chuck. This is working great. This script also turns all the inactive layers in the current artboard into active ones (layer Visibility off --> on). Do you know why that is happening? Thanks in advance. 

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
Participant ,
Oct 05, 2022 Oct 05, 2022

Copy link to clipboard

Copied

It actually turns on all the inactive layers above the text layer in the artboard to be precise. 

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 ,
Oct 06, 2022 Oct 06, 2022

Copy link to clipboard

Copied

Now that you mention it, I think so. It has to do with the fact that while it's looping through the layers, it is making that layer active, which also makes it visible. Ill6have to see about that.

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 ,
Oct 06, 2022 Oct 06, 2022

Copy link to clipboard

Copied

This script should keep the layers visibility the same.

#target photoshop

var doc = app.activeDocument;
var oldPref = app.preferences.rulerUnits;
app.preferences.rulerUnits = Units.PIXELS;

var ab, aLayer, aW, aH

var defaultValue = '';
var desktopHead = prompt("Paste your new headline", defaultValue);

var docLayers = doc.layers.length; //getting top layers because artboards are top layers

for(var i=0;i<docLayers;i++){
    aLayer = doc.layers[i];
    ab = artboard_rectangle(aLayer);
    aW = ab[2]-ab[0];
    aH = ab[3]-ab[1];
    if((aW == 1000 && aH == 1000) || (aW == 400 && aH == 500)){//add more sizes here
            findTextLayer (aLayer)
            }//end if for artboard size
    }//end for loop

app.preferences.rulerUnits = oldPref;

function findTextLayer(pLayer){
    var layLen = pLayer.layers.length;
    for(var j = 0;j<layLen;j++){
        var layerRef = pLayer.layers[j];
        if(pLayer.layers[j].typename == 'LayerSet'){
            findTextLayer (pLayer.layers[j]);           
            }//end if for finding layerset
        else{
            if (layerRef.kind === LayerKind.TEXT) {
                if(layerRef.textItem.font === "Arial-BoldMT"){//make sure you have correct font name
                    layerRef.textItem.contents = desktopHead;
                    }//end if for text font
                }//end if for layerkind text            
            }//end else
        };//end for loop
    
    };//end function

function artboard_rectangle(layer)
    {
    try {        
        var r    = new ActionReference();    
        r.putProperty(stringIDToTypeID("property"), stringIDToTypeID("artboard"));
        if (layer) r.putIdentifier(stringIDToTypeID("layer"), layer.id);
        else       r.putEnumerated(stringIDToTypeID("layer"), stringIDToTypeID("ordinal"), stringIDToTypeID("targetEnum"));
        var d = executeActionGet(r).getObjectValue(stringIDToTypeID("artboard")).getObjectValue(stringIDToTypeID("artboardRect"));
        var bounds = new Array();
        bounds[0] = d.getUnitDoubleValue(stringIDToTypeID("left"));
        bounds[1] = d.getUnitDoubleValue(stringIDToTypeID("top")); 
        bounds[2] = d.getUnitDoubleValue(stringIDToTypeID("right"));
        bounds[3] = d.getUnitDoubleValue(stringIDToTypeID("bottom"));                                

        return bounds;
        }
    catch(e) { alert(e); }
    }

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
Participant ,
Oct 06, 2022 Oct 06, 2022

Copy link to clipboard

Copied

This is perfect, Chuck. Thanks again for all the effort. You are amazing 👏 

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 ,
Oct 06, 2022 Oct 06, 2022

Copy link to clipboard

Copied

Glad it's working out. There always seems to be some little glitch, when writing scripts.

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
Participant ,
Oct 20, 2022 Oct 20, 2022

Copy link to clipboard

Copied

Hey Chuck, I have been trying to modify this script but couldn't achieve the right results. If you could help me, it would be really appreciated. Totally two things that I would like to modify it, 

 

1) Whenever there is the word "discount" in the sentence "Get 20% discount" which is given as input, the word "Discount" alone has to turn Green in color.  Get 20% discount --> Get 20% discount
2) Whenever there is a number "1" in the sentence "Get 20% discount1", the number has to turn into a superscript.  Get 20% discount1 ---> Get 20% discount¹

Thanks in advance. 

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