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

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

328

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

Community Expert , 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};
};

Votes

Translate

Translate
LEGEND , 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(',')

 

Votes

Translate

Translate
Community Expert , Jul 22, 2021 Jul 22, 2021

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

Votes

Translate

Translate
Adobe
LEGEND ,
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')

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
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')

 

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
LEGEND ,
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(',')

 

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

Copy link to clipboard

Copied

That should be faster. 

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
LEGEND ,
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 😉

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
Community Expert ,
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. 

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
Community Expert ,
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};
};

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

Copy link to clipboard

Copied

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

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
LEGEND ,
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?

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