Place the script in the following location: C:\Program Files\Adobe\Adobe InDesign CS6\Scripts\startup scripts
If you close the document the script will automatically put the metadata in your indesign file (use ctrl+w or menu -> file -> close option to close the file)
Code:
#targetengine session
//if you want to test the script for your active document, comment the below line else copy the script in your startup folder
app.menuActions.itemByName("Close").eventListeners.add("beforeInvoke", function()
{
var myDoc = app.activeDocument;
var docTitleText="";
var docDescripText="";
app.findGrepPreferences = app.changeGrepPreferences = null;
app.findGrepPreferences.findWhat = '.+';
found = app.activeDocument.findGrep (true);
for (j = found.length-1; j >=0 ; j--)
{
var foundText = found.contents;
//You can define multiple Paragraph style for Document Title
if(found.texts[0].appliedParagraphStyle.name=="docTitle1")
{
docTitleText=found.contents;
}
else if(found.texts[0].appliedParagraphStyle.name=="docTitle2")
{
docTitleText=docTitleText + " " + found.contents;
}
else if(found.texts[0].appliedParagraphStyle.name=="docTitle3")
{
docTitleText=docTitleText + " " + found.contents;
}
//You can define multiple Paragraph style for Document Description
else if(found.texts[0].appliedParagraphStyle.name=="docDescription1")
{
docDescripText=found.contents;
}
else if(found.texts[0].appliedParagraphStyle.name=="docDescription2")
{
docDescripText=docDescripText + " " + found.contents;
}
else if(found.texts[0].appliedParagraphStyle.name=="docDescription3")
{
docDescripText=docDescripText + " " + found.contents;
}
}
with (myDoc.metadataPreferences){
author = "My Name";
documentTitle = docTitleText;
description = docDescripText;
}
});
Vandy