I am using ExtendScript to work on metadata information of .indd
files in InDesignCC 2019.
My requirement is that I need to access all individual links metadata associated with the .indd
file and see whether any of the links metadata is missing DocumentID
and InstanceID
. If any of the links metadata do not have a value for DocumentID
and/or InstanceID
properties then I need to display the file name associated with that link, indicating that, that particular file is missing a DocumentID
and/or InstanceID
.
I have used the below script to access the meta data of .indd
file.
$.level=0
// load XMP Library
function loadXMPLibrary() {
if (!ExternalObject.AdobeXMPScript) {
try{ExternalObject.AdobeXMPScript = new ExternalObject('lib:AdobeXMPScript');}
catch (e){alert('Unable to load the AdobeXMPScript library!'); return false;}
}
return true;
}
var myFile= app.activeDocument.fullName;
var myXmp = null;
// check library and file
if (loadXMPLibrary() && myFile !== null) {
xmpFile = new XMPFile(myFile.fsName, XMPConst.FILE_INDESIGN, XMPConst.OPEN_FOR_UPDATE);
myXmp = xmpFile.getXMP();
$.writeln(xmpFile.getPacketInfo());
}
if (myXmp){
$.writeln (myXmp);
$.writeln (XMPFile.getFormatInfo(XMPConst.FILE_INDESIGN));
}
Can any one help me how can I proceed further in this?
Once you've obtained the XMP from the link, i.e. xmpFile.getXMP()
, you'll need to:
Utilize the getProperty()
method to retrieve the value of a specific metadata property.
Typically the DocumentID
and InstanceID
will be associated with the NS_XMP_MM
schema namespace, which is described as:
NS_XMP_MM
The XML namespace for the XMP digital asset management schema.
For instance, to obtain the DocumentID
you'll do something like the following:
var documentID = allXMP.getProperty(XMPConst.NS_XMP_MM, 'DocumentID', XMPConst.STRING);
The gist below (example.jsx) performs the following:
Checks whether a .indd
file is open and notifies the user if there is not one open.
Loads the AdobeXMPScript XMP Library
Checks that the status of all Links are "OK", i.e. it checks that they are not "Modified", nor "Missing". If any link status is not "OK" the user is asked to update their status to "OK".
Checks whether each linked asset has a DocumentID
and InstanceID
and logs their values to the JavaScript Console.
For any linked asset that does not have a DocumentID
and/or InstanceID
an alert dialog appears indicating the name and path to the linked asset.
example.jsx
$.level=0;
// Warn if there are no documents open.
if (!app.documents.length) {
alert('Open a document and try again.', 'Missing Document', false);
exit();
}
var doc = app.activeDocument;
// load XMP Library
function loadXMPLibrary() {
if (!ExternalObject.AdobeXMPScript) {
try {
ExternalObject.AdobeXMPScript = new ExternalObject('lib:AdobeXMPScript');
} catch (e) {
alert('Failed loading AdobeXMPScript library\n' + e.message, 'Error', true);
return false;
}
}
return true;
}
// Check all link statuses are be ok.
function linksStatusCheck(doc) {
for (var i = 0, len = doc.links.length; i < len; i++) {
if (doc.links[i].status !== LinkStatus.NORMAL) {
alert('The status of all links must be OK \nPlease update link status ' +
'via the Links panel and try again', 'Link Status', true);
exit();
}
}
return true;
}
function checkLinksXMP(doc) {
for (var i = 0, len = doc.links.length; i < len; i++) {
var linkFilepath = File(doc.links[i].filePath).fsName;
var linkFileName = doc.links[i].name;
var xmpFile = new XMPFile(linkFilepath, XMPConst.FILE_INDESIGN, XMPConst.OPEN_FOR_READ);
var allXMP = xmpFile.getXMP();
// Retrieve values from external links XMP.
var documentID = allXMP.getProperty(XMPConst.NS_XMP_MM, 'DocumentID', XMPConst.STRING);
var instanceID = allXMP.getProperty(XMPConst.NS_XMP_MM, 'InstanceID', XMPConst.STRING);
// Useful for testing purposes....
// Log properties for each link to the console.
$.writeln('linkName: ' + linkFileName);
$.writeln('filePath: ' + linkFilepath);
$.writeln('DocumentID: ' + documentID);
$.writeln('InstanceID: ' + instanceID);
$.writeln('-------------------------------------');
// Notify user when XMP is missing...
if (!documentID && !instanceID) {
alert('Link missing DocumentID and InstanceID\n' +
'Name: ' + linkFileName + '\n\n' +
'Path: ' + linkFilepath, 'Missing XMP', true);
} else if (!documentID) {
alert('Link missing DocumentID\n' +
'Name: ' + linkFileName + '\n\n' +
'Path: ' + linkFilepath, 'Missing XMP', true);
} else if (!instanceID) {
alert('Link missing InstanceID\n' +
'Name: ' + linkFileName + '\n\n' +
'Path: ' + linkFilepath, 'Missing XMP', true);
}
}
}
if (loadXMPLibrary() && linksStatusCheck(doc)) {
checkLinksXMP(doc);
}