Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
974 views
in Technique[技术] by (71.8m points)

javascript - Find and replace text in multiple Photoshop files?

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?

I have tried finding and replacing software (including powerful tools like Power Grep) but they do not work with psd files... Maybe Photoshop variables? However, they only work for one document at once...

Thanks!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Use something like the script below. For more info check out your Photoshop JavaScript Reference pdf in your Photoshop install directory.

var dir = new Folder('/c/temp')
var files = dir.getFiles("*.psd");

for (var i = 0; i < files.length; i++) {
    var doc = app.open(files[i]);

    for (var j= 0; j < doc.artLayers.length; j++) {
        var lyr = doc.artLayers[j];

        if (lyr.kind == LayerKind.TEXT) {
            var lyr = doc.artLayers[j];
            lyr.textItem.contents = lyr.textItem.contents.replace("search","replace"); 
        }
     }

    doc.close(SaveOptions.SAVECHANGES)
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...