Copy link to clipboard
Copied
I've seen lots of script info here but yet to find anything about doing what I would like to do. I want to parse the contents of the text within the file to build a keyword list. It's not a perfect solution but I think it can work if you create an exclusion list such as do not include; in, high, used, meet, on, from, and, or, but, the it, buy, talk etc...and then pull the next ten keywords by word frequency and past them into the meta keywords.
I have also seen that none of the scripts in this site ever include a boolean operation to ignure fields that have already been filled out. In that way if the field was manually filled out or automatically filled out, it will not attempt to overwrite the metadata, only if the field is blank...
This would solve a lot of headaches if a firm has files that get filled out by staff, then the script ignores the pre-filled fields and just fills in blank fields.
Of course I would also liek to fill in other fields and toggle security fields as well... I would also like the author field to be set to the UserID of the person logging in to the computer like is done in most corporate environments.
I am also curious if there is a way to set a template file that is automatically pulled by InDesign every time a file is created that already defines the metadata fields but not using XMP to import...I mean to do so transparently to the user.
Hi @bcn020900a1 , the methods and properties for the metadataPreferences are here:
Sounds like you are looking for a complex script, but what you are describing is doable. This example would get all of the words in a document and make an array of words that are not in the exception array Iāve named xList:
var doc = app.documents.item(0);
var md = doc.metadataPreferences;
//list of exce
...
Copy link to clipboard
Copied
Hi @bcn020900a1 , the methods and properties for the metadataPreferences are here:
Sounds like you are looking for a complex script, but what you are describing is doable. This example would get all of the words in a document and make an array of words that are not in the exception array Iāve named xList:
var doc = app.documents.item(0);
var md = doc.metadataPreferences;
//list of exceptions
var xlist = ["for", "the", "of", "are", "I"]
//all words in the doc
var dw = doc.stories.everyItem().words.everyItem().getElements();
var kw = []
//make the keyword array
for (var i = 0; i < dw.length; i++){
if (!checkItem(xlist, dw[i].contents) && !checkItem(kw, dw[i].contents)) {
$.writeln(dw[i].contents)
kw.push(dw[i].contents)
}
};
md.keywords = kw
/**
* Checks if an item is in an array
* @ param the array to check
* @ param the item to look for
* @ return true if the item is in the array
*
*/
function checkItem(a, obj) {
for (var i = 0; i < a.length; i++) {
if (a[i] === obj) {
return true;
}
}
return false;
}
Look at the append method to load a default info from xml. The default ID xml is stored here:
/Users/username/Library/Application Support/Adobe/XMP/Metadata Templates/InDesign Default.xmp
If I edit that file I could load it into a new doc like this:
var doc = app.documents.item(0);
var temp = Folder.userData.fsName + "/Adobe/XMP/Metadata Templates/InDesign Default.xmp"
var td = app.documents.add();
var md = td.metadataPreferences;
md.append(temp, true)
Copy link to clipboard
Copied
I like thie simple approach to loading the data from the default.xmp script. Thank you for that. How would I add a check to have the script determine if the XML data was already filled out and of so not overwrite the data?
Copy link to clipboard
Copied
Thank you Rob, The path to the API was the most helpful thing.