Skip to main content
Participant
Feb 16, 2008 5:35 PM UTC
Question

script to insert file name into keywords field of same file

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 is closed to new replies. Start a new post to keep the conversation going.

13 replies

Known Participant
Feb 21, 2009 9:19 PM UTC
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
Translate
Participant
Feb 12, 2009 11:22 PM UTC
Paul, thanks so much for the script(s). It rocked!
Translate
Paul Riggott
Inspiring
Dec 3, 2008 7:50 PM UTC
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;

}

}

Translate
Paul Riggott
Inspiring
Dec 3, 2008 11:26 AM UTC
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.
Translate
Participant
Dec 3, 2008 10:35 AM UTC
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
Translate
Paul Riggott
Inspiring
Dec 2, 2008 12:12 PM UTC
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);

}

}
Translate
Participant
Dec 2, 2008 10:08 AM UTC
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!
Translate
Participating Frequently
Nov 30, 2008 8:13 PM UTC
Thanks. It works

Good Luck.
______
My Si tes
Translate
Kasyan Servetsky
Legend
Mar 2, 2008 8:39 PM UTC
It proved to be so simple. :-)

Thank you, Paul.

Kasyan
Translate
Paul Riggott
Inspiring
Feb 27, 2008 8:39 PM UTC
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;
}
Translate