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

Adding file name to Title metadata

Participant ,
Nov 17, 2020 Nov 17, 2020

Copy link to clipboard

Copied

I have over 1000 files where I need to put the file name (minus extension) into the title metadata in order to automatically fill the Alt text for a website. 

I found a script on here from a while ago but it doesnt appear to do anything when I select it. I think it was wrote for CS5.

Can anyone help? 

Thanks

TOPICS
Metadata , Scripting

Views

544

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
LEGEND ,
Nov 17, 2020 Nov 17, 2020

Copy link to clipboard

Copied

LATEST

#target bridge
if(BridgeTalk.appName == 'bridge'){
try{

//create menu
var ftCmd = MenuElement.create('command', 'Filename to Title', 'at the end of Tools');
var ftContCmd = MenuElement.create('command', 'Filename to Title', 'after Thumbnail/Open', this.menuID); //add to Contextual menu
}
catch(e){
alert(e + ' ' + e.line);
}
}

ftCmd.onSelect = function(){
ftAddFilenameToTitle();
}

ftContCmd.onSelect = function(){
ftAddFilenameToTitle();
}

function ftAddFilenameToTitle(){
try{
var ftThumbs = app.document.selections; //get selected thumbnails
if (!ftThumbs.length) return; //nothing selected
if (ExternalObject.AdobeXMPScript == undefined) ExternalObject.AdobeXMPScript = new ExternalObject('lib:AdobeXMPScript');
for(var a in ftThumbs){ //loop through thumbs
var ftTitle = ftThumbs[a].name; //get filename
//remove filename after last dash character
//to remove filename after dash, uncomment lines
//~ ftTitle = ftTitle.split('-');
//~ if(ftTitle.length > 1){
//~ ftTitle.length--;
//~ }
//~ ftTitle = ftTitle.join('-');
//remove filename after last period character
ftTitle = ftTitle.split('.');
if(ftTitle.length > 1){
ftTitle.length--;
}
ftTitle = ftTitle.join('.');
var ftMeta = ftThumbs[a].synchronousMetadata;
var ftXMP = new XMPMeta(ftMeta.serialize());
ftXMP.deleteProperty(XMPConst.NS_DC, 'title'); //delete old title
ftXMP.appendArrayItem(XMPConst.NS_DC, 'title', ftTitle, 0, XMPConst.ALIAS_TO_ALT_TEXT); //write new title
ftXMP.setQualifier(XMPConst.NS_DC, 'title[1]', 'http://www.w3.org/XML/1998/namespace', 'lang', 'x-default');
var ftUpdatedPacket = ftXMP.serialize(XMPConst.SERIALIZE_OMIT_PACKET_WRAPPER | XMPConst.SERIALIZE_USE_COMPACT_FORMAT);
ftThumbs[a].metadata = new Metadata(ftUpdatedPacket); //write to file
}
}
catch(e){
alert(e + ' ' + e.line);
}
}

Votes

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