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

script to find and replace in all document

Participant ,
Sep 13, 2017 Sep 13, 2017

Copy link to clipboard

Copied

I have the below script which find and replace only only one sentence I want to 2 different sentence should be find and replaced, need modification, thanks in advance

#target photoshop

if (app.documents.length > 0) {

          for (var n = 0; n < app.documents.length; n++) {

                    app.activeDocument = app.documents;

                    app.activeDocument.suspendHistory("replace text", "main()")

                    }

          };

// the opertation;

function main () {

          var myDocument = app.activeDocument;

          var theLayers = collectTextLayers(myDocument, []);

          if (theLayers.length > 0) {

                    var theArray1 = ["FIND OUT MORE"];

                    var theArray2 = ["ĎALŠIE INFORMÁCIE"];

                    for (var a = 0; a < theLayers.length; a++) {

                              for (var b = 0; b < theArray1.length; b++) {

                                        var theString = theLayers.textItem.contents;

                                        while (theString.indexOf(theArray1) != -1) {

                                                  theString = theString.replace(theArray1, theArray2)

                                                  };

                                        theLayers.textItem.contents = theString;

                                        }

                              }

                    }

          };
   

////// function collect all layers //////

function collectTextLayers (theParent, allLayers) {

          if (!allLayers) {var allLayers = new Array};

          else {};

          for (var m = theParent.layers.length - 1; m >= 0;m--) {

                    var theLayer = theParent.layers;

// apply the function to layersets;

                    if (theLayer.typename == "ArtLayer") {

                              if (theLayer.kind == LayerKind.TEXT) {allLayers.push(theLayer)};

                              }

                    else {

                              allLayers = (collectTextLayers(theLayer, allLayers))

// this line includes the layer groups;

//                              allLayers.push(theLayer);

                              }

                    };

          return allLayers

          };

Views

330

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 1 Correct answer

Community Expert , Sep 13, 2017 Sep 13, 2017

First iff you may want to post over on

Photoshop Scripting

and secondly that looks like DOM code and you may get considerably better performance with AM code.

Is there any way of accessing Find and Replace Text... through scripting?

Votes

Translate

Translate
Adobe
Community Expert ,
Sep 13, 2017 Sep 13, 2017

Copy link to clipboard

Copied

LATEST

First iff you may want to post over on

Photoshop Scripting

and secondly that looks like DOM code and you may get considerably better performance with AM code.

Is there any way of accessing Find and Replace Text... through scripting?

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