Copy link to clipboard
Copied
Hello,
I am trying to find a way to automatically insert metadata into my document through paragraph style in indesign cs5.5.
This will be myDocument title, the Author name and myDocument description.
Is there anyone who can help me with this project?
Thanks.
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()
{
v
...Copy link to clipboard
Copied
Hi abmiss1,
I have a doubt with your above request, what i understood!
If the the paragraph style is "myDocument title" means the contents insert to : XMP Document title.
If the the paragraph style is "Author Name" means the contents insert to : XMP Author name.
If the the paragraph style is "myDocument description" means the contents insert to : XMP Description.
Please find the below JS cod its simply created the XMP meta information.
var myDocument = app.activeDocument;
with (myDocument.metadataPreferences){
author = "Adobe";
copyrightInfoURL = "http://www.adobe.com";
copyrightNotice = "This document is copyrighted.";
copyrightStatus = CopyrightStatus.yes;
description = "Example of xmp metadata scripting in InDesign CS";
documentTitle = "XMP Example";
jobName = "XMP_Example_2003";
keywords = ["animal", "mineral", "vegetable"];
}
Otherwise please clearly expalin what is your requirement.
thx,
csm_phil
Copy link to clipboard
Copied
Try this,
var myDoc = app.activeDocument;
var authorText, docDescripText;
app.findGrepPreferences = app.changeGrepPreferences = null;
app.findGrepPreferences.findWhat = '.+';
found = app.activeDocument.findGrep (true);
for (j = 0; j < found.length; j++){
var foundText = found
if(found
{
authorText=found
}
else if(found
{
docDescripText=found
}
}
with (myDoc.metadataPreferences){
author = authorText;
documentTitle = myDoc.name.split(".indd")[0];
description = docDescripText;
}
Vandy
Copy link to clipboard
Copied
Thank you very much Vandy. The script work good. The only thing I want to ask you again is ( maybe I wasn't explicit on my original post 😞 The author name will always be the same but the Document Title and the Document Description will varry, this is why I wanted to do it with paragraph style. Also I was wondering if I can apply like 2 or 3 styles to the Document descrition at the same time. So in summary (author name="My Name", Document Title = "Par Style1" "Par Style2" And my Document Description will be also define with multiple paragraph styles.
I also need help to make the srypt run automatically as I open any document or close it.
Thank so much for your help.
Copy link to clipboard
Copied
Thank you Phil. Sorry for the confusion in my original post, I try to explain little bit my need in my answer to Vandy.
Please refer to it if you can help. Again thank you for your help.
Copy link to clipboard
Copied
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
//You can define multiple Paragraph style for Document Title
if(found
{
docTitleText=found
}
else if(found
{
docTitleText=docTitleText + " " + found
}
else if(found
{
docTitleText=docTitleText + " " + found
}
//You can define multiple Paragraph style for Document Description
else if(found
{
docDescripText=found
}
else if(found
{
docDescripText=docDescripText + " " + found
}
else if(found
{
docDescripText=docDescripText + " " + found
}
}
with (myDoc.metadataPreferences){
author = "My Name";
documentTitle = docTitleText;
description = docDescripText;
}
});
Vandy
Copy link to clipboard
Copied
Thank you Vandy, this script work like a charm.