my script is doing everything i want except it is converting all spaces and periods to semicolons in the final metatag and i cannot figure out why.
It will be VERY obvious that the attached script is nothing but a bunch of snippets clipped together to perform most of what i want...
I want to run this script at the end as i am completing a project to insert the needed metatags.
i want the project name
i want the copyright info
i want keywords to include all images used in the document
i want to be able to add keywords.
to run this script you will need a character style called KeywordsCStyle
//-----document title and copyright---------
var myDocument = app.activeDocument;
with (myDocument.metadataPreferences){
//author = "Adobe";
copyrightInfoURL = "UPMC.com"
copyrightNotice = "© 2014 UPMC";
copyrightStatus = CopyrightStatus.yes;
//description = "Example of xmp metadata scripting in InDesign CS";
documentTitle = myDocument.name.split(".indd")[0];
//jobName = "XMP_Example_2003";
//var myNewContainer = createContainerItem("http://ns.adobe.com/xap/1.0/", "email");
//setProperty("http://ns.adobe.com/xap/1.0/", "email/*[1]", "someone@adobe.com");
}
//----------------------------------------------------
with (myDocument.metadataPreferences){
//author = "scott rudy";
documentTitle = myDocument.name.split(".indd")[0];
}
//-------------------------------------------------//
//var curDocTitle = app.activeDocument.metadataPreferences.documentTitle;
//var curAuthor = app.activeDocument.metadataPreferences.author;
var curKeywords = app.activeDocument.metadataPreferences.keywords;
Array.prototype.unique = function (){
var r = new Array();
o:for(var i = 0, n = this.length; i < n; i++){
for(var x = 0, y = r.length; x < y; x++){
if(r[x]==this[i]) continue o;}
r[r.length] = this[i];}
return r;
}
function addXMP(/*find GREP*/findString, /*para style*/paraStyle, /*chr style*/chrStyle, /*insert to*/XMPdest){
// reset search fields
app.findGrepPreferences = NothingEnum.nothing;
app.changeGrepPreferences = NothingEnum.nothing;
// setting search parameters
if(findString)app.findGrepPreferences.findWhat = findString;
if(paraStyle)app.findGrepPreferences.appliedParagraphStyle = paraStyle;
if(chrStyle)app.findGrepPreferences.appliedCharacterStyle = chrStyle;
switch (XMPdest){
// insert keywords
case "Keywords":
var myKeywords = app.activeDocument.findGrep();
var myKeys = Array();
// loop through keywords and get contents
for(var i = 0; i < myKeywords.length; i++)
myKeys.push(myKeywords[i].contents);
//myKeys.sort();
// delete duplicates
//myKeys = myKeys.unique();
// insert Keywords to document XMP
app.activeDocument.metadataPreferences.keywords = myKeys;
break;
// Heading search/insert
case "Heading":
var myHeading = app.activeDocument.findGrep();
app.activeDocument.metadataPreferences.documentTitle = myHeading[0].contents;
break;
// Author search/insert
// case "Author":
// var myAuthor = app.activeDocument.findGrep();
// app.activeDocument.metadataPreferences.author = myAuthor[0].contents;
// break;
}
}
// copy all image names //----------------------------------------------//
f = app.activeDocument.textFrames.add({geometricBounds:[0,0,"20mm","20mm"]});
f.contents = app.activeDocument.links.everyItem().name.join("\r");
f.parentStory.texts[0].select();
//-----------change character style-------------------//
var cName = "KeywordsCStyle";
var mCstyle = app.activeDocument.characterStyles.item(cName);
if (mCstyle.isValid)
app.selection[0].applyCharacterStyle(mCstyle);
//---------------------------------------//
app.copy();
//-----------------------------------------------------------------------//
// add Keywords
addXMP("\\w{1,}","","KeywordsCStyle","Keywords");
// add Heading
//addXMP("","HeadingPStyle","","Heading");
//add Author
addXMP("","AuthorPStyle","","Author");
//
//----delete image names textbox--------
f.remove();