• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers

Copy filename to "Creator Job Title"

Explorer ,
Feb 18, 2019 Feb 18, 2019

Copy link to clipboard

Copied

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

TOPICS
Scripting

Views

918

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Guide , Feb 18, 2019 Feb 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(/\.[^\.]+$/, '')
  
...

Likes

Translate

Translate
Guide ,
Feb 18, 2019 Feb 18, 2019

Copy link to clipboard

Copied

#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); 
        
    }
};

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Feb 18, 2019 Feb 18, 2019

Copy link to clipboard

Copied

Hi SuperMerlin.

Wow. Just wow! It works perfectly. You really saved my day.

Hope I can return the favor some day!

Thanks!

Kind regards

/Henrik

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Feb 18, 2019 Feb 18, 2019

Copy link to clipboard

Copied

Hi SuperMerlin

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

Thanks in advance.

Kind regards

/Henrik

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Feb 18, 2019 Feb 18, 2019

Copy link to clipboard

Copied

Yes

Change:

var Title = decodeURI(selectedFile.name).replace(/\.[^\.]+$/, '')

To

var Title = decodeURI(selectedFile.name);

Best of luck.

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Feb 18, 2019 Feb 18, 2019

Copy link to clipboard

Copied

Damn, you're fast!

Thanks a lot!

Kind regards

/Henrik

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 18, 2019 Feb 18, 2019

Copy link to clipboard

Copied

LATEST

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.

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines