Skip to main content
feinschmecker
Known Participant
February 18, 2019
Answered

Copy filename to "Creator Job Title"

  • February 18, 2019
  • 1 reply
  • 1556 views

Hi all

I stumbled across this script from Paul Riggott. It copies the file name to the Title field. Tested it and it works like a charm. So far so good.

  1. #target bridge    
  2.    if( BridgeTalk.appName == "bridge" ) {   
  3. FT = MenuElement.create("command", "Add FileName to Title", "at the end of Tools"); 
  4. FT.onSelect = function () {  
  5.    AddFilenameToTitle(); 
  6.    } 
  7. function AddFilenameToTitle(){ 
  8. var thumbs = app.document.selections;  
  9. if(!thumbs.length) return; 
  10. if (ExternalObject.AdobeXMPScript == undefined)  ExternalObject.AdobeXMPScript = new ExternalObject("lib:AdobeXMPScript"); 
  11. for(var a in thumbs){ 
  12. var selectedFile = thumbs.spec;     
  13. var Title = decodeURI(selectedFile.name).replace(/\.[^\.]+$/, '') 
  14.       var myXmpFile = new XMPFile( selectedFile.fsName, XMPConst.UNKNOWN, XMPConst.OPEN_FOR_UPDATE);  
  15.   var myXmp = myXmpFile.getXMP(); 
  16.         myXmp.deleteProperty(XMPConst.NS_DC, "title"); 
  17.         myXmp.appendArrayItem(XMPConst.NS_DC, "title", Title, 0, XMPConst.ALIAS_TO_ALT_TEXT); 
  18.         myXmp.setQualifier(XMPConst.NS_DC, "title[1]", "http://www.w3.org/XML/1998/namespace", "lang", "x-default"); 
  19.         if (myXmpFile.canPutXMP(myXmp)) {  
  20.         myXmpFile.putXMP(myXmp); 
  21.          myXmpFile.closeFile(XMPConst.CLOSE_UPDATE_SAFELY);  
  22.          }  
  23.     } 

I need the filename to be inserted into the "Creator: Job Title" field. I haven't written a line of code in my life, but I tried to replace all instances of "title" (case sensitive) with "photoshop:AuthorsPosition"... Should have known it didn't work.

Any help would be greatly appreciated!

Kind regards

/Henrik

This topic has been closed for replies.
Correct answer SuperMerlin
#target bridge   
   if( BridgeTalk.appName == "bridge" ) {  
FAP = MenuElement.create("command", "Add FileName to Author Position", "at the end of Tools");
}
FAP.onSelect = function () { 
var thumbs = app.document.selections; 
if(!thumbs.length) return;
if (ExternalObject.AdobeXMPScript == undefined)  ExternalObject.AdobeXMPScript = new ExternalObject("lib:AdobeXMPScript");
for(var a in thumbs){
var selectedFile = thumbs.spec;
var Title = decodeURI(selectedFile.name).replace(/\.[^\.]+$/, '')
      var myXmpFile = new XMPFile( selectedFile.fsName, XMPConst.UNKNOWN, XMPConst.OPEN_FOR_UPDATE); 
  var myXmp = myXmpFile.getXMP();
        myXmp.deleteProperty(XMPConst.NS_PHOTOSHOP, "AuthorsPosition");
        myXmp.setProperty(XMPConst.NS_PHOTOSHOP, "AuthorsPosition", Title);
        if (myXmpFile.canPutXMP(myXmp)) { 
        myXmpFile.putXMP(myXmp);
         myXmpFile.closeFile(XMPConst.CLOSE_UPDATE_SAFELY); 
        
    }
};

1 reply

SuperMerlin
SuperMerlinCorrect answer
Inspiring
February 18, 2019
#target bridge   
   if( BridgeTalk.appName == "bridge" ) {  
FAP = MenuElement.create("command", "Add FileName to Author Position", "at the end of Tools");
}
FAP.onSelect = function () { 
var thumbs = app.document.selections; 
if(!thumbs.length) return;
if (ExternalObject.AdobeXMPScript == undefined)  ExternalObject.AdobeXMPScript = new ExternalObject("lib:AdobeXMPScript");
for(var a in thumbs){
var selectedFile = thumbs.spec;
var Title = decodeURI(selectedFile.name).replace(/\.[^\.]+$/, '')
      var myXmpFile = new XMPFile( selectedFile.fsName, XMPConst.UNKNOWN, XMPConst.OPEN_FOR_UPDATE); 
  var myXmp = myXmpFile.getXMP();
        myXmp.deleteProperty(XMPConst.NS_PHOTOSHOP, "AuthorsPosition");
        myXmp.setProperty(XMPConst.NS_PHOTOSHOP, "AuthorsPosition", Title);
        if (myXmpFile.canPutXMP(myXmp)) { 
        myXmpFile.putXMP(myXmp);
         myXmpFile.closeFile(XMPConst.CLOSE_UPDATE_SAFELY); 
        
    }
};
feinschmecker
Known Participant
February 18, 2019

Hi SuperMerlin

I have a little follow-up question: Is it possible to include the file extension?

Thanks in advance.

Kind regards

/Henrik

Stephen Marsh
Community Expert
Community Expert
February 18, 2019

Damn, you're fast!

Thanks a lot!

Kind regards

/Henrik


For completeness, the equivalent ExifTool command would be as follows...

Without Extension:

exiftool '-XMP-photoshop:AuthorsPosition<${filename;s/\.[^.]*$//}' -r 'Path to Folder or File'

With Extension:

exiftool '-XMP-photoshop:AuthorsPosition<${filename}' -r 'Path to Folder or File'

NOTE: These commands are formatted for the Mac OS, Windows OS uses double straight " quote marks.