Welcome Dialog

Welcome to the Community!

We have a brand new look! Take a tour with us and explore the latest updates on Adobe Support Community.


Filter Photoshop Keywords | Find & Replace

Explorer ,
Jul 22, 2021 Jul 22, 2021

Copy link to clipboard

Copied

Let's say my Photoshop keywords are:

cat; dog; mouse

 

I want to filter through the keywords, find "cat" and replace it with "elephant" via javascript. 

 

How do I filter through photoshop's keywords to replace keywords?

TOPICS
Actions and scripting, macOS

Views

113

Likes

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

Adobe Community Professional , Jul 22, 2021 Jul 22, 2021
// 2021, use it at your own risk; if (documents.length > 0) { var myDocument = activeDocument; var theKeyw = myDocument.info.keywords; alert (theKeyw.join("\n")); var newKeyw = new Array; var check = false; for (var m = 0; m < theKeyw.length; m++) { var thisOne = theKeyw[m]; if (thisOne == "cat") {newKeyw.push("elephant"); check = true} else {newKeyw.push (thisOne)} }; if (check == true) {myDocument.info.keywords = newKeyw}; };

Likes

Translate

Translate
Adobe Community Professional , Jul 22, 2021 Jul 22, 2021
inf.keywords = (inf = activeDocument.info).keywords .toString().replace(/cat/gi, 'elephant').split(',') or: with(activeDocument.info) keywords = keywords.toString() .split('cat').join('elephant').split(',')

Likes

Translate

Translate
Adobe Community Professional , Jul 22, 2021 Jul 22, 2021
If the OP wants to run the Script on a largish batch of images it might pay off. 

Likes

Translate

Translate
Adobe Community Professional ,
Jul 22, 2021 Jul 22, 2021

Copy link to clipboard

Copied

'cat; dog; mouse'.replace(/cat/, 'elephant')

or:

'cat; dog; mouse'.split('cat').join('elephant')

Likes

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
Explorer ,
Jul 22, 2021 Jul 22, 2021

Copy link to clipboard

Copied

I tried the below, because I need to call to the the Document Keywords first before I can search for cat - right? I tried the below but it didnt work. 

 

 

 

var doc = app.activeDocument;
var docKeywords = doc.info.keywords;

docKeywords.replace(/cat/, 'elephant')
or 
docKeywords.split('cat').join('elephant')

 

Likes

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
Adobe Community Professional ,
Jul 22, 2021 Jul 22, 2021

Copy link to clipboard

Copied

 

inf.keywords = (inf = activeDocument.info).keywords
.toString().replace(/cat/gi, 'elephant').split(',')

 

or:

 

with(activeDocument.info)
	keywords = keywords.toString()
	.split('cat').join('elephant').split(',')

 

Likes

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
Adobe Community Professional ,
Jul 22, 2021 Jul 22, 2021

Copy link to clipboard

Copied

That should be faster. 

Likes

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
Adobe Community Professional ,
Jul 22, 2021 Jul 22, 2021

Copy link to clipboard

Copied

Yes it is, but the speed really counts when there are really many items 😉

Likes

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
Adobe Community Professional ,
Jul 22, 2021 Jul 22, 2021

Copy link to clipboard

Copied

If the OP wants to run the Script on a largish batch of images it might pay off. 

Likes

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
Adobe Community Professional ,
Jul 22, 2021 Jul 22, 2021

Copy link to clipboard

Copied

// 2021, use it at your own risk;
if (documents.length > 0) {
var myDocument = activeDocument;
    var theKeyw = myDocument.info.keywords;
    alert (theKeyw.join("\n"));
    var newKeyw = new Array;
    var check = false;
    for (var m = 0; m < theKeyw.length; m++) {
        var thisOne = theKeyw[m];
        if (thisOne == "cat") {newKeyw.push("elephant");
        check = true}
        else {newKeyw.push (thisOne)}
    };
    if (check == true) {myDocument.info.keywords = newKeyw};
};

Likes

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
Explorer ,
Jul 22, 2021 Jul 22, 2021

Copy link to clipboard

Copied

Thank you once again. I had no clue how to do that. 🙂

Likes

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
Adobe Community Professional ,
Jul 22, 2021 Jul 22, 2021

Copy link to clipboard

Copied

LATEST

You are aware that there are four different keyword namespaces in EXIF/XMP? Do you want to limit this to dc:subject or address the others as well?

Likes

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