Copy link to clipboard
Copied
I'm trying to figure out how to read the XMP Title of a document, and compare it to the file name. I keep coming up empty on google, and their AI is recommending a function that doesn't exist as per usual.
From what I'm seeing in the scripting documents, there is only:
app.activeDocument.XMPString
How do I just parse out the title? I keep getting results for Photoshop and InDesign, but those functions don't appear to cross over into Illustrator.
<dc:title>
<rdf:Alt>
<rdf:li xml:lang="x-default">Untitled-2</rdf:li>
</rdf:Alt>
</dc:title>
Hi @wckdtall,
To get the title you can directly read using the following
app.activeDocument.name
but still if you required to get the title from the document XMP, please try
var regex = /<rdf:li[^>]*xml:lang="x-default"[^>]*>(.*?)<\/rdf:li>/;
var match = app.activeDocument.XMPString.match(regex);
if (match && match[1]) {
var title = match[1];
alert("Title found : " + title);
} else {
alert("Title not found");
}
To add another solution, AdobeXMPScript makes it easy to parse.
Copy link to clipboard
Copied
Hi @wckdtall,
To get the title you can directly read using the following
app.activeDocument.name
but still if you required to get the title from the document XMP, please try
var regex = /<rdf:li[^>]*xml:lang="x-default"[^>]*>(.*?)<\/rdf:li>/;
var match = app.activeDocument.XMPString.match(regex);
if (match && match[1]) {
var title = match[1];
alert("Title found : " + title);
} else {
alert("Title not found");
}
Copy link to clipboard
Copied
Thanks! I'll give this regex a shot. Do you know if the xml markup is the same for all filetypes? Eps, pdf, ai etc?
Are there any other functions built in to get/set properties? Love the idea of regex for this since I was just asking to read, just wondering if I'll need additional lookarounds.
Like the idea of regex since I only have to read at this point,
Copy link to clipboard
Copied
To add another solution, AdobeXMPScript makes it easy to parse.
Copy link to clipboard
Copied
Thanks! Works like a charm! I don't know if I'd say it's easy, but I can't really wrap my mind around xmp, cause it always seems to be a diffrent formatted xml, and use different functions between all the programs.
Is there a straight forward guide you've come across that explains it? I guess since most of extendscript is a single package, once it gets into different libraries, it's a stumbling block every time for me.
Copy link to clipboard
Copied
See Scripting Access to XMP Metadata in JavaScript Tools Guide CC.pdf.
Copy link to clipboard
Copied
Thanks! Looks like this documentation doesn't have an example with Illustrator's XMPString, your example is clear on how to handle. XMPString is the equivalent to xmpMetadata.rawData in photoshop.
//Photoshop example
var xmp = new XMPMeta(app.activeDocument.xmpMetadata.rawData);
//Illustrator example
var xmp = new XMPMeta(app.activeDocument.XMPString);
After the library is loaded, looks like all is needed to read the title directly is:
var xmp = new XMPMeta(app.activeDocument.XMPString);
alert(xmp.getLocalizedText(XMPConst.NS_DC,"title", null, null));
Copy link to clipboard
Copied
Illustrator's XMPString is an Illustrator feature, see Illustrator JavaScript Scripting Reference.pdf.
If you want to use the exact same process in Illustrator, Photoshop, or another app, you can get the XMP string directly from the file via XMPFile. This can be found in the JavaScript Tools Guide.