You can utilize the setProperty()
method in the AdobeXMPScript library to create and set the value for DocumentID
and InstanceID
Below are a couple of helper functions for adding a DocumentID
and InstanceID
.
// Note: This function works on macOS only
function generateUUID() {
var cmd = 'do shell script "uuidgen | tr -d " & quoted form of "-"';
return app.doScript(cmd, ScriptLanguage.applescriptLanguage);
}
// Add an XMP property and Value.
function addXmpPropertyAndValue(filePath, xmpProperty, xmpValue) {
var xmpFile = new XMPFile(filePath, XMPConst.FILE_UNKNOWN, XMPConst.OPEN_FOR_UPDATE);
var allXMP = xmpFile.getXMP();
allXMP.setProperty(XMPConst.NS_XMP_MM, xmpProperty, xmpValue);
if (xmpFile.canPutXMP(allXMP)) {
xmpFile.putXMP(allXMP);
}
xmpFile.closeFile(XMPConst.CLOSE_UPDATE_SAFELY);
// Useful for testing purposes....
alert('Added: ' + xmpProperty + '
' +
'value: ' + xmpValue + '
' +
'Path: ' + filePath, 'Updated XMP', false);
}
To add an instanceID
invoke the addXmpPropertyAndValue
function as follows:
// The `linkFilepath` argument should be the filepath to the Link you want to update
addXmpPropertyAndValue(linkFilepath, 'InstanceID', 'xmp.iid:' + generateUUID());
To add an DocumentID
invoke the addXmpPropertyAndValue
function as follows:
// The `linkFilepath` argument should be the filepath to the Link you want to update
addXmpPropertyAndValue(linkFilepath, 'DocumentID', 'xmp.did:' + generateUUID());
Additional Note:
When generating the value(s) for DocumentID
and InstanceID
the guidelines state:
An ID should be guaranteed to be globally unique (in practical terms, this means that the probability of a collision is so remote as to be effectively impossible). Typically 128- or 144-bit numbers are used, encoded as hexadecimal strings
The excerpt (above) can be found on page 19 of Partner's guide to XMP for Dynamic Media (PDF)
Unfortunately, ExtendScript does not provide a built-in feature to generate a globally unique identifier (GUID). However macOS does include uuidgen
which is a command-line utility/library for
generating unique identifiers (UUID/GUID).
The helper function (above):
function generateUUID() {
var cmd = 'do shell script "uuidgen | tr -d " & quoted form of "-"';
return app.doScript(cmd, ScriptLanguage.applescriptLanguage);
}
runs on macOS only. It utilizes AppleScript to run the uuidgen
command.
You may want to generate the identifier this way instead of your current randomString(32)
function call.