Skip to main content
toddl62332479
Participant
May 22, 2017
Question

How can I modify IPTC headers with JSX script, without opening images.

  • May 22, 2017
  • 2 replies
  • 4267 views

I'd like to use Photoshop, and scripting, to modify several IPTC fields in a JPEG, without actually opening the JPEG, and then also rename the JPEG.

Right now, I've got a .JSX script I wrote that will do the following:

1) Ask the user to point to a directory containing JPEG files

2) Ask the user to input a caption

3) Open each JPEG in the directory, modify the Author, Caption, and several other fields

4) Save-As the JPEG to a new directory, with a different name

5) Close the JPEG

This JSX works great right now.  But if there are 100 images, then it take a long time to complete this task.

I have another .JSX script that will complete some of this work without opening the JPEG in Photoshop.  But this .JSX script only modifies XMP data.  That information is not visible from the Windows file system when I right-click and ask for "details."

How can I write a .JSX script to modify the IPTC metadata without actually opening the JPG, and how can I get Photoshop to rename the file as well?

Thanks,

This topic has been closed for replies.

2 replies

Participating Frequently
April 16, 2019

Bonjour

You can also use ExifTool on the command line - see HERE

JJMack
Community Expert
Community Expert
May 22, 2017

Photoshop can not rename files but you can use Javascript file system support to rename files.    For Photoshop to change IPTC metadata not only would it need to open the files it would also need to write the file.  The Bridge can read and write metadata without opening the document in Photoshop and Bridge can rename files.   Bridge can be scripted but I have never written a Bridge script and there is some kind a Bridge Talk interface between Bridge scripts and Photoshop scripts.  You may want to look at Bridge scripting.

JJMack
toddl62332479
Participant
May 22, 2017

In the last couple of hours, I've written a script that allows Photoshop to modify IPTC information without opening the JPG, and also allows it to rename the JPG without opening or re-saving it.

What I'm missing now is an understanding of how to identify all the metadata that it's possible to change, and how to do that. I can change author and description and copyright notice.  But I want to modify more.

How can I insert my code here to share, and not have it look like a mess?

Joachim Hiller
Known Participant
April 16, 2019

To be honest no, but I do have a work-a-round that works for me.

Here is a Photoshop script that could easiliy be changed for Bridge.

/*

    Example on how to populate ArtworkOrObject , locationShown and locationCreated fields

*/

#target photoshop;

app.bringToFront();

if(documents.length){

if (ExternalObject.AdobeXMPScript == undefined)  ExternalObject.AdobeXMPScript = new ExternalObject("lib:AdobeXMPScript");

xmp = new XMPMeta( app.activeDocument.xmpMetadata.rawData );

xmp.setProperty("http://ns.useplus.org/ldf/xmp/1.0/","ImageSupplierImageID", activeDocument.name);

newxmp = new XMPMeta(ArtworkOrObject("1944-12-20T00:00Z","Source field","Copyright field","Title field","Your name","123456789"));

XMPUtils.appendProperties(newxmp, xmp, XMPConst.APPEND_ALL_PROPERTIES);

newxmp = new XMPMeta(locationShown("Daisy Hill","Bradford","W. Yks","England","+44","In the stars"));

XMPUtils.appendProperties(newxmp, xmp, XMPConst.APPEND_ALL_PROPERTIES);

newxmp = new XMPMeta(locationCreated("Denby Dale","York","W. Yks","England","+44","Out There"));

XMPUtils.appendProperties(newxmp, xmp, XMPConst.APPEND_ALL_PROPERTIES);

app.activeDocument.xmpMetadata.rawData = xmp.serialize();

};

function ArtworkOrObject(date,Source,Copy,Title,Creator,SInvNo){

if(date == undefined) date = ''; if(Source == undefined) Source = '';

if(Copy == undefined) Copy = ''; if(Title == undefined) Title ='';

if(Creator == undefined) Creator = ''; if(SInvNo == undefined) SInvNo = '';

var s ="<x:xmpmeta xmlns:x=\"adobe:ns:meta/\" x:xmptk=\"Adobe XMP Core 5.3-c011 66.145661, 2012/02/06-14:56:27        \">";

s+="<rdf:RDF xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\">";

s+="<rdf:Description rdf:about=\"\" xmlns:Iptc4xmpExt=\"http://iptc.org/std/Iptc4xmpExt/2008-02-29/\">"

s+="<Iptc4xmpExt:ArtworkOrObject><rdf:Bag><rdf:li><rdf:Description ";     

s+=" Iptc4xmpExt:AODateCreated=\"" + date + "\"  Iptc4xmpExt:AOSource=\"" +Source + "\" ";

s+=" Iptc4xmpExt:AOSourceInvNo=\""+SInvNo + "\"  Iptc4xmpExt:AOCopyrightNotice=\"" + Copy +"\">";

s+="<Iptc4xmpExt:AOTitle><rdf:Alt><rdf:li xml:lang=\"x-default\">" + Title;

s+=" </rdf:li></rdf:Alt></Iptc4xmpExt:AOTitle><Iptc4xmpExt:AOCreator><rdf:Seq><rdf:li>";

s+=  Creator +"</rdf:li></rdf:Seq></Iptc4xmpExt:AOCreator></rdf:Description>";

s+="</rdf:li></rdf:Bag></Iptc4xmpExt:ArtworkOrObject></rdf:Description></rdf:RDF></x:xmpmeta>";

return s;

};

function locationShown(SubLoc,City,State,CountryName,CountryCode,WorldRegion){

if(SubLoc == undefined) SubLoc = ''; if(City == undefined) City = '';

if(State == undefined) State = ''; if(CountryName == undefined) CountryName = '';

if(CountryCode == undefined) CountryCode = ''; if(WorldRegion == undefined) WorldRegion = '';

var s ="<x:xmpmeta xmlns:x=\"adobe:ns:meta/\" x:xmptk=\"Adobe XMP Core 5.3-c011 66.145661, 2012/02/06-14:56:27        \">"

s +="<rdf:RDF xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\">";

s += "<rdf:Description rdf:about=\"\"   xmlns:Iptc4xmpExt=\"http://iptc.org/std/Iptc4xmpExt/2008-02-29/\">";

s +="<Iptc4xmpExt:LocationShown><rdf:Bag><rdf:li rdf:parseType=\"Resource\">";

s +="<Iptc4xmpExt:Sublocation>" +SubLoc +"</Iptc4xmpExt:Sublocation>";

s +="<Iptc4xmpExt:City>"+City +"</Iptc4xmpExt:City>";

s +="<Iptc4xmpExt:ProvinceState>"+ State +"</Iptc4xmpExt:ProvinceState>";

s +="<Iptc4xmpExt:CountryName>" + CountryName + "</Iptc4xmpExt:CountryName>";

s +="<Iptc4xmpExt:CountryCode>" + CountryCode + "</Iptc4xmpExt:CountryCode>";

s +="<Iptc4xmpExt:WorldRegion>" + WorldRegion + "</Iptc4xmpExt:WorldRegion>";

s +="</rdf:li></rdf:Bag></Iptc4xmpExt:LocationShown></rdf:Description></rdf:RDF></x:xmpmeta>";

return s;

};

function locationCreated(SubLoc,City,State,CountryName,CountryCode,WorldRegion){

if(SubLoc == undefined) SubLoc = ''; if(City == undefined) City = '';

if(State == undefined) State = ''; if(CountryName == undefined) CountryName = '';

if(CountryCode == undefined) CountryCode = ''; if(WorldRegion == undefined) WorldRegion = '';

var s ="<x:xmpmeta xmlns:x=\"adobe:ns:meta/\" x:xmptk=\"Adobe XMP Core 5.3-c011 66.145661, 2012/02/06-14:56:27        \">"

s +="<rdf:RDF xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\">";

s += "<rdf:Description rdf:about=\"\"   xmlns:Iptc4xmpExt=\"http://iptc.org/std/Iptc4xmpExt/2008-02-29/\">";

s +="<Iptc4xmpExt:LocationCreated><rdf:Bag><rdf:li rdf:parseType=\"Resource\">";

s +="<Iptc4xmpExt:Sublocation>" +SubLoc +"</Iptc4xmpExt:Sublocation>";

s +="<Iptc4xmpExt:City>"+City +"</Iptc4xmpExt:City>";

s +="<Iptc4xmpExt:ProvinceState>"+ State +"</Iptc4xmpExt:ProvinceState>";

s +="<Iptc4xmpExt:CountryName>" + CountryName + "</Iptc4xmpExt:CountryName>";

s +="<Iptc4xmpExt:CountryCode>" + CountryCode + "</Iptc4xmpExt:CountryCode>";

s +="<Iptc4xmpExt:WorldRegion>" + WorldRegion + "</Iptc4xmpExt:WorldRegion>";

s +="</rdf:li></rdf:Bag></Iptc4xmpExt:LocationCreated></rdf:Description></rdf:RDF></x:xmpmeta>";

return s;

};


Thank you SuperMerlin, I need it for Photoshop .