Javascript Metadata & Parse content

New Here ,
Aug 22, 2022 Aug 22, 2022

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.

TOPICS
Scripting

Views

73

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Aug 22, 2022 Aug 22, 2022

Hi @bcn020900a1 , the methods and properties for the metadataPreferences are here:

 

https://www.indesignjs.de/extendscriptAPI/indesign-latest/#MetadataPreference.html#d1e409118__d1e409418

 

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
...

Likes

Translate

Translate
Community Expert ,
Aug 22, 2022 Aug 22, 2022

Copy link to clipboard

Copied

Hi @bcn020900a1 , the methods and properties for the metadataPreferences are here:

 

https://www.indesignjs.de/extendscriptAPI/indesign-latest/#MetadataPreference.html#d1e409118__d1e409...

 

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)

 

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Aug 25, 2022 Aug 25, 2022

Copy link to clipboard

Copied

LATEST

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?

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Aug 22, 2022 Aug 22, 2022

Copy link to clipboard

Copied

Thank you Rob, The path to the API was the most helpful thing.

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines