Skip to main content
Participant
July 21, 2017
Question

Find and replace text in Photoshop files

  • July 21, 2017
  • 1 reply
  • 1647 views

Hi

I have 100 similar PSD files with same word written inside it. but name of the files is diffrent

All 100 PSD files has one word written in it. for example. word is "TestWord"

Name if the PSD files is like

apple.psd

banana.psd

orange.psd

peas.psd

pears.psd

now I want to replace "TestWord" with name of the files. like

in apple.psd file, "TestWord" will be replaced with word "Apple"

in banana.psd file, "TestWord" will be replaced with word "banana"

please suggest some script to achieve this

regards

This topic has been closed for replies.

1 reply

c.pfaffenbichler
Community Expert
Community Expert
July 21, 2017

// 2017, use it at your own risk;

#target photoshop

if (app.documents.length > 0) {

var myDocument = activeDocument;

var theString = "TestWord";

var theReplacementString = myDocument.name.match(/(.*)\.[^\.]+$/)[1];

var textLayers = collectAndChangeTextLayers(app.activeDocument, [], theString, theReplacementString);

};

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

function collectAndChangeTextLayers (theParent, allLayers, theString, theReplacementString) {

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

  else {};

  var theNumber = theParent.layers.length - 1;

  for (var m = theNumber; m >= 0;m--) {

  var theLayer = theParent.layers;

// apply the function to layersets;

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

// edit typelayers;

  if (theLayer.kind == LayerKind.TEXT) {

  while (theLayer.textItem.contents.indexOf(theString) != -1) {theLayer.textItem.contents = theLayer.textItem.contents.replace(theString, theReplacementString)};

  allLayers.push(theLayer)

  }

  }

  else {

  allLayers = collectAndChangeTextLayers(theLayer, allLayers, theString, theReplacementString)

// this line includes the layer groups;

// allLayers.push(theLayer);

  }

  };

  return allLayers

  };

(edited)

Participant
July 23, 2017

hi c.pfaffenbichler

one more question, assume, there is text file containing one word in each line . for example:

apple

banana

orange

pears

peas

I have a PSD file having multiple text layers, and only one word written in all layers, for example sample,

so , looking for a script which take a word from txt file and replace this sample word and save the file

I can create action for saving the file. but i need a script which can take word from the txt file one by one

please help.

Participant
July 24, 2017

hi

can anyone help me with below query

one more question, assume, there is text file containing one word in each line . for example:

apple

banana

orange

pears

peas

I have a PSD file having multiple text layers, and only one word written in all layers, for example sample,

so , looking for a script which take a word from txt file and replace this sample word and save the file

I can create action for saving the file. but i need a script which can take word from the txt file one by one

please help.