Copy link to clipboard
Copied
Is there a way auto-populate the file info of my document using paragraph styles? basically like variable text.
or is there a script that would fill in the file info with text that is assigned a paragraph so i could run the same script on multiple documents but it will fill in the doc specific info?
found is an arraty so you need to use the subscript operator to reference the items within the array. Try the following
var myDoc = app.activeDocument;
var docTitle = "";
var docDesc = "";
var docKeywords = "";
var docCopyright = "";
app.findGrepPreferences = app.changeGrepPreferences = null;
app.findGrepPreferences.findWhat = '.+';
found = app.activeDocument.findGrep(true);
for (j = found.length - 1; j >= 0; j--) {
if (found[j].texts[0].appliedParagraphStyle.name == "main_title") {
...
Copy link to clipboard
Copied
app.activeDocument.metadataPreferences gives to access to the File Info. So I'm thinking you could use FindGrep() to get the contents of the first paragraph using your main_title style, and copy it to app.activeDocument.metadataPreferences.description, for example.
Copy link to clipboard
Copied
I found some language that looks like it should work ... but gives me an error, any thoughts on how to fix?
var myDoc = app.activeDocument;
var docTitle ="";
var docDesc ="";
var docKeywords ="";
var docCopyright ="";
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;
if(found.texts[0].appliedParagraphStyle.name == "main_title") {
docTitle=found.contents;
}
else if(found.texts[0].appliedParagraphStyle.name == "metadata_desc") {
docDesc=found.contents;
}
else if(found.texts[0].appliedParagraphStyle.name == "metadata_keywords") {
docKeywords=found.contents;
}
else(found.texts[0].appliedParagraphStyle.name == "metadata_copyright") {
docCopyright=found.contents;
}
}
with (myDoc.metadataPreferences){
documentTitle = docTitle;
copyrightNotice = docCopyright;
copyrightStatus = CopyrightStatus.yes;
description = docDesc;
keywords = [docKeywords];
}
Copy link to clipboard
Copied
Copy link to clipboard
Copied
found is an arraty so you need to use the subscript operator to reference the items within the array. Try the following
var myDoc = app.activeDocument;
var docTitle = "";
var docDesc = "";
var docKeywords = "";
var docCopyright = "";
app.findGrepPreferences = app.changeGrepPreferences = null;
app.findGrepPreferences.findWhat = '.+';
found = app.activeDocument.findGrep(true);
for (j = found.length - 1; j >= 0; j--) {
if (found[j].texts[0].appliedParagraphStyle.name == "main_title") {
docTitle = found[j].contents;
}
else if (found[j].texts[0].appliedParagraphStyle.name == "metadata_desc") {
docDesc = found[j].contents;
}
else if (found[j].texts[0].appliedParagraphStyle.name == "metadata_keywords") {
docKeywords = found[j].contents;
}
else (found[j].texts[0].appliedParagraphStyle.name == "metadata_copyright") {
docCopyright = found[j].contents;
}
}
with (myDoc.metadataPreferences) {
documentTitle = docTitle;
copyrightNotice = docCopyright;
copyrightStatus = CopyrightStatus.yes;
description = docDesc;
keywords = [docKeywords];
}
-Manan
Copy link to clipboard
Copied
Thank you so much! I'm still learning to understand arrays!
Copy link to clipboard
Copied
No worries, we are here to help. Happy learning.
-Manan
Copy link to clipboard
Copied
Another suggestion, you might wanna use the appliedParagraphStyle property of findGrepPreferences to find the text with the required paragraphstyle instead of looping on all the text in the document.
Also reset the findGrepPreferences at the end
app.findGrepPreferences = null;
-Manan
Copy link to clipboard
Copied
that is a good idea! thank you!