script to insert file name into IPTC Headline field

General Discussion of Scripting for Adobe Bridge

Moderators: Tom, Kukurykus

Mike Hale

script to insert file name into IPTC Headline field

Post by Mike Hale »

Code: Select all#target bridge // let EntendScript know what app the script is for

addNametoMeta = {};// create an object

addNametoMeta.execute = function(){// create a method for that object
var sels = app.document.selections;// store the array of selected files
for (var i = 0; i < sels.length; i++){//loop though that array

var md = sels.synchronousMetadata;// get the metadata for the file
md.namespace = "http://ns.adobe.com/photoshop/1.0/";// set the namespace
md.Source = sels.name;//set the porperty
}
}

// this script only works in bridge
if (BridgeTalk.appName == "bridge"){
//creage the munuItem
var menu = MenuElement.create( "command", "Save Filename in Metadata", "at the end of Tools");
menu.onSelect = addNametoMeta.execute;
}

Here is the script with short comments. Things like 'MenuElement.create' you can find in the Bridge guide.

For what namespace to use, I open a file in Photoshop. Choose File-File Info. Then play around with entering data the looking in the advance section to see where that data is stored. There may be a better way but it works for me.

Mike
xbytor

script to insert file name into IPTC Headline field

Post by xbytor »

goofy167 wrote:Being a novice if even a small number of comments were included I believe I could understand better how it works. I am not a C expert

Make sure that you pick up 'JavaScript: The Definitive Guide' by David Flanagan. It's my desk reference for JS language stuff. It also has a lot of JS web info in there, but I just ignore that part...

-X
goofy167

script to insert file name into IPTC Headline field

Post by goofy167 »

Code: Select allmd.Headline =  sels.name.substring(0,sels.name.lastIndexOf('.'));


This removes the extension from the file name, I am still trying to unravel it. I also have a two letter photographer initial at the end of the file name I need to delete.

American Dipper CT.jpg

Is that hard to do?
Mike Hale

script to insert file name into IPTC Headline field

Post by Mike Hale »

Code: Select allmd.Headline =  sels.name.substring(0,sels.name.lastIndexOf('.')-3);

substring takes two numbers as arguments. substring(startCharPosition,endCharPosition). lastIndexOf returns the charPotition of the search char. So in your example 'American Dipper CT.jpg ' it would return 18.

Most things that are numbered in javascript start with 0. So for that file sels.name.substring(0,sels.name.lastIndexOf('.')-3) = sels.name.substring(0,15).

The -3 part takes care of the two letter initials and the space before.

You will run into trouble if there are any exceptions to that pattern. For example a file with more or less than two initials.

Mike
goofy167

script to insert file name into IPTC Headline field

Post by goofy167 »

That's very cool and so simple. Thank you I have learned a great deal from this thread and plan to buy the Javascript book today with all the great sales on.
Joshua007

script to insert file name into IPTC Headline field

Post by Joshua007 »

Where I download this script Make Hale has created, so that I can use it in Adobe Bridge.

Many thanks

Joshua007