Skip to main content
Participant
February 16, 2008
Question

script to insert file name into keywords field of same file

  • February 16, 2008
  • 13 replies
  • 3971 views
Hello,

search a solution, a Script or another, which writes the file name into keywords field of same file (Metadata: Description/Keywords) in "photoshop", "bridge" or better in "Lightroom" .
I found this topic from Mike Hale http://www.ps-scripts.com/bb/viewtopic.php?t=1330
It's possible this script to change this in such a way that it does this:
"script to insert file name into keywords field of same file"

Thanks and best greetings

Wolfgang
This topic has been closed for replies.

13 replies

Known Participant
February 21, 2009
You
i can
do that with a Bridge script ... but it's much easier to just use Phil Harvey's ExifTool for this task.

-- Olaf
Participant
February 12, 2009
Paul, thanks so much for the script(s). It rocked!
Paul Riggott
Inspiring
December 3, 2008
This works in CS2:-



#target bridge

if( BridgeTalk.appName == "bridge" ) {

nameDescription = MenuElement.create("command", "AddName to Description", "at the beginning of Thumbnail");

}

nameDescription .onSelect = function () {

nameToDescription();

}

function nameToDescription(){

var items = app.document.selections;

for (var i = 0; i < items.length; ++i) {

var item = items;

var m = item.synchronousMetadata;

filenameToDesc(m, item.name.slice(0,-4));

}

function filenameToDesc(metadata, Description) {

var strTmpl = "name2Desc";

var strUser = Folder.userData.absoluteURI;

var filTmpl = new File(strUser + "/Adobe/XMP/Metadata Templates/" + strTmpl + ".xmp");

var fResult = false;

try

{ if (filTmpl.exists)

filTmpl.remove();

fResult = filTmpl.open("w");

if (fResult) {

filTmpl.writeln("<x:xmpmeta xmlns:x=\"adobe:ns:meta/\" x:xmptk=\"3.1.2-113\">");

filTmpl.writeln(" <rdf:RDF xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\">");

filTmpl.writeln(" <rdf:Description rdf:about=\"\" xmlns:dc=\"http://purl.org/dc/elements/1.1/\">");

filTmpl.writeln("<dc:description>");

filTmpl.writeln("<rdf:Alt>");

filTmpl.writeln("<rdf:li xml:lang=\"x-default\">"+Description+"</rdf:li>");

filTmpl.writeln("</rdf:Alt>");

filTmpl.writeln("</dc:description>");

filTmpl.writeln(" </rdf:Description>");

filTmpl.writeln(" </rdf:RDF>");

filTmpl.writeln("</x:xmpmeta>");

fResult = filTmpl.close();

metadata.applyMetadataTemplate(strTmpl, "replace");

filTmpl.remove();

} }

catch(e)

{ fResult = false; }

return fResult;

}

}

Paul Riggott
Inspiring
December 3, 2008
I wrote this using CS3, I have just tested it and found there is a problem using it on CS2 (works fine on CS3 and CS4)
I wonder if you are using CS2?
If so I will have another look and see if there is a way to do it.
Participant
December 3, 2008
Dear Paul R,

Thank you for such a fast reply!
I have managed to run the script in Bridge, and it seems processing some kind of information when i select the picture and choose from the right click dropdown menu "Add FileName to Description" and it Bridge shows, that the file has been modified today, this instant, but nothing appear in the IPTC description field. I cannot imagine that I could have done something wrong, but still, maybe? Do you have any ideas?

Mailis
Paul Riggott
Inspiring
December 2, 2008
Here you are, this should do the job.
The Files should be selected and then use Right Click Menu - "Add FileName to Description"



#target bridge

if( BridgeTalk.appName == "bridge" ) {

addFileName = MenuElement.create("command", "Add FileName to Description", "at the end of Thumbnail");

}

addFileName.onSelect = function () {

addFileNameToDescription();

}

function addFileNameToDescription(){

var sels = app.document.selections;

for (var i = 0; i < sels.length; i++){

var md = sels.synchronousMetadata;

md.namespace = "http://purl.org/dc/elements/1.1/";

md.description = sels.name.slice(0,-4);

}

}
Participant
December 2, 2008
Hello!

I am wondering, whether someone could help me on my silly predicament: I would like to change this script so that it automatically ads filename to IPTC Description field. (It is necessary for me in order to use a script LabelGraphic in Indesign, which extraxts the label from XMP description.) As i know absolutely nothing about scripting, the only idea that came to me is to change the line
md.Source = sels.name;
to
md.Description = sels.name;

But this seems not to work. I have no idea why or what have I done wrong. could you please help me on that, I would be very grateful!
Especcially, if it could be possible to make the script add to IPTC Description only the filename, without an extension.

Thanks a million in advance!
Participating Frequently
November 30, 2008
Thanks. It works

Good Luck.
______
My Si tes
Kasyan Servetsky
Legend
March 2, 2008
It proved to be so simple. :-)

Thank you, Paul.

Kasyan
Paul Riggott
Inspiring
February 27, 2008
Try this, it should now add the filename to the END of your Keywords.
Paul.

#target bridge
addNametoMeta = {};

addNametoMeta.execute = function(){
var sels = app.document.selections;
for (var i = 0; i < sels.length; i++){

var md = sels.synchronousMetadata;
md.namespace = "http://ns.adobe.com/photoshop/1.0/";
md.Keywords = md.Keywords + ";"+sels.name;
}
}

// this script only works in bridge
if (BridgeTalk.appName == "bridge"){

var menu = MenuElement.create( "command", "Save Filename in Keywords", "at the end of Tools");
menu.onSelect = addNametoMeta.execute;
}