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

Find and replace text in multiple Photoshop files?

Guest
Dec 10, 2013 Dec 10, 2013

Hi there,

Let us say I have six Photoshop files: 1.psd, 2.psd, ..., 6.psd. All of these files contain the word “LoremIpsum” in random text layers, within each document. Is there a way I can search for “LoremIpsum” in all documents and replace it with “Dolor Sit Amet”, all in one go? This is just an example, I need to replace various words, not just one.

I have tried "batch find and replace" software (including powerful tools like Power Grep) but they do not work with psd files… Is there a javascript of external plugin for this kind of task?

Thanks!

TOPICS
Actions and scripting
26.2K
Translate
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
New Here ,
Feb 24, 2014 Feb 24, 2014

i have the same proplem with you . But now after i tried reinstall PTS cs6 , ít can't be open . Please help me !

Translate
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
Guest
Feb 24, 2014 Feb 24, 2014

Chisaicoi let us know what error you receive so I (and most likely more experienced members) can help...

In the meantime, no progress for me, still stuck...

Translate
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 ,
Dec 10, 2013 Dec 10, 2013

This should work on all open documents if the Type Layers’ content is uniform.

// replace text elements in type layers;

// 2013, use it at your own risk;

#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 = ["LoremIpsum"];

                    var theArray2 = ["Dolor Sit Amet"];

                    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

          };

Translate
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 ,
Sep 13, 2017 Sep 13, 2017

I have 2 different words sets, this script is for single combination, can u plz modify... thanks in advance

Translate
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 ,
Sep 14, 2017 Sep 14, 2017

// replace text elements in type layers;

// 2017, use it at your own risk;

#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 theArray = [["TEST", "123"], ["HAHAHA", "456"]];

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

                    replaceText (theArray[0], theArray[1])

                    }

          };

////// reoplace text //////

function replaceText (replaceThis, replaceWith) {

// =======================================================

var idreplace = stringIDToTypeID( "replace" );

    var desc22 = new ActionDescriptor();

    var idnull = charIDToTypeID( "null" );

        var ref3 = new ActionReference();

        var idPrpr = charIDToTypeID( "Prpr" );

        var idreplace = stringIDToTypeID( "replace" );

        ref3.putProperty( idPrpr, idreplace );

        var idTxLr = charIDToTypeID( "TxLr" );

        var idOrdn = charIDToTypeID( "Ordn" );

        var idAl = charIDToTypeID( "Al  " );

        ref3.putEnumerated( idTxLr, idOrdn, idAl );

    desc22.putReference( idnull, ref3 );

    var idUsng = charIDToTypeID( "Usng" );

        var desc23 = new ActionDescriptor();

        var idfind = stringIDToTypeID( "find" );

        desc23.putString( idfind, replaceThis );

        var idreplace = stringIDToTypeID( "replace" );

        desc23.putString( idreplace, replaceWith );

        var idcheckAll = stringIDToTypeID( "checkAll" );

        desc23.putBoolean( idcheckAll, true );

        var idFwd = charIDToTypeID( "Fwd " );

        desc23.putBoolean( idFwd, true );

        var idcaseSensitive = stringIDToTypeID( "caseSensitive" );

        desc23.putBoolean( idcaseSensitive, false );

        var idwholeWord = stringIDToTypeID( "wholeWord" );

        desc23.putBoolean( idwholeWord, false );

        var idignoreAccents = stringIDToTypeID( "ignoreAccents" );

        desc23.putBoolean( idignoreAccents, true );

    var idfindReplace = stringIDToTypeID( "findReplace" );

    desc22.putObject( idUsng, idfindReplace, desc23 );

executeAction( idreplace, desc22, DialogModes.NO );

};

Translate
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 ,
Sep 14, 2017 Sep 14, 2017

thanks its working, but it dosent work in photoshop cc 2017 but it works on cs6,

Translate
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 ,
Sep 14, 2017 Sep 14, 2017

Start a new thread if you need help.

Translate
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 ,
Sep 15, 2017 Sep 15, 2017

it shows this error, need help

Translate
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 ,
Sep 15, 2017 Sep 15, 2017

So start a new thread.

Error: And provide more details about the file on which the error occurs.

Translate
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 ,
Sep 15, 2017 Sep 15, 2017

Or wrap the code in the replaceText-function in a try-clause.

Translate
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 ,
Sep 15, 2017 Sep 15, 2017

?

Translate
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 ,
Sep 15, 2017 Sep 15, 2017
Translate
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 Beginner ,
Jan 09, 2020 Jan 09, 2020

Hey there, I am looking to do the same thing within photoshop cc19 and was wondering if you started a new thread to help deal with your error or if you found a solution to this problem? I am also getting similar errors when I try to run this in cc19.  

 

Cheers,

 

Marty

Translate
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
LEGEND ,
Jan 10, 2020 Jan 10, 2020
LATEST

Please start a new thread so we can figure out what you need.

Translate
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