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

Indesign script to automatically insert document title metadata based on file name

Community Beginner ,
Jul 21, 2021 Jul 21, 2021

Copy link to clipboard

Copied

Hi

I've been having problems with client changing file names when sending back amends and not knowing which job or version the file relates to. 

Is there a simple script which will insert the file name into the document title metadata field? Or it could go into the descriptin field if easier. That way even if they chage the file title I can still find the original job title

On save/export would be great if possible?

Thanks so much! 

TOPICS
How to , Import and export , Scripting

Views

1.5K

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 ,
Jul 21, 2021 Jul 21, 2021

Copy link to clipboard

Copied

Have a look at: File > File Info, to see if that would be of any help.

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
Community Expert ,
Jul 21, 2021 Jul 21, 2021

Copy link to clipboard

Copied

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
Community Expert ,
Jul 21, 2021 Jul 21, 2021

Copy link to clipboard

Copied

This has actually come up before. You can try saving this script into your Scripts>startup scripts folder and restart ID:

 

 

 

var el = app.eventListeners.add("afterSave", onSaveKW );

/**
* Function to run after a Save
*  the event 
*/
function onSaveKW(evt){
    var kws = app.activeDocument.metadataPreferences.keywords;
    var kwp = "oname"
    var n = evt.parent.name
    if (!checkKeywords(kws, kwp)) {
        kws.unshift("oname:" + n)
        app.activeDocument.metadataPreferences.keywords = kws
    } 
}

/**
* Checks if a keyword starting with oname: exists 
*  the keyword array to check 
*  the prefix string 
*  false if keyword does not exist 
* 
*/
function checkKeywords(a, p){
    var b = false
    for (var i = 0; i < a.length; i++){
        if (a[i].split(":")[0] == p) {
            b=true
        } 
    }  
    return  b
}

 

 

 

The startup script listens for an after save event, and sets the doc name as a keyword, if it’s the first save the name gets added as oname:YourFileName.indd.

 

Here I created a new file and named it MyIDFile.indd and then did a save as with a different name and the file info keeps the original name:

 

Screen Shot 26.png

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
Community Expert ,
Jul 21, 2021 Jul 21, 2021

Copy link to clipboard

Copied

Also, the downside of saving the original name as a keyword, is the client could edit the keywords after the name change. If that’s a potential problem the original name could be inserted into the RAW XMP data as a custom node:

 

 

Screen Shot 27.png

 

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
Advisor ,
Jul 22, 2021 Jul 22, 2021

Copy link to clipboard

Copied

Hello @ChristianAsprenoGLOBE 

 

The below script will write the file name into the document title field every time the document is Saved or Save As.

Save this script here: Applications⁩ ▸ ⁨Adobe InDesign ▸ ⁨Scripts⁩ ▸ ⁨startup scripts⁩ folder and restart Indesign:

#targetengine "session"

function saveFileMetaData() {
    if(app.layoutWindows.length == 0) return;
    else if (!app.activeDocument.saved) {
        alert('Sorry, there was a problem and the document was not saved.');
        return;
        }
   doc = app.activeDocument; 
   var fileName = doc.name.replace(/.indd$/i, "");
   var myMetaData = doc.metadataPreferences;
   myMetaData.documentTitle = fileName;
}

app.addEventListener('afterSave', saveFileMetaData, false);
app.addEventListener('afterSaveAs', saveFileMetaData, false);

 

Regards,

Mike

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
Community Expert ,
Jul 22, 2021 Jul 22, 2021

Copy link to clipboard

Copied

Hi @Mike Bro, I think @ChristianAsprenoGLOBE wants the original file name saved to metadata—the current file name (doc.name) could be different.

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
Advisor ,
Jul 22, 2021 Jul 22, 2021

Copy link to clipboard

Copied

Hi @rob day 

I see you point, but if the script is only installed on the OP's computer the document title meta data would be whatever they last Saved or Saved As before sending the file off to their client.

 

Regards,

Mike

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
Community Beginner ,
Jul 22, 2021 Jul 22, 2021

Copy link to clipboard

Copied

Thanks all! Im going to give this one a try now and will let you know the results. I think the document title is what we're after so it sounds perfect! 

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
Community Beginner ,
Nov 16, 2023 Nov 16, 2023

Copy link to clipboard

Copied

LATEST

This is really useful, thanks!

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