Copy link to clipboard
Copied
Hello everyone,
in my document, the authors are styled with a specific paragraph style. My script harvests this specific style and inserts the (cleaned up) contents into the document’s metadata field "metadataPreferences.author". This all works very well, but I always get quotes around the author names:
I looked up the object model and "metadataPreferences.author" only accepts a string. It doesn’t matter, if I use semicolon or comma separated authors, both separators cause the qouted form – no separators, no quotes.
The code I use for injecting into InDesigns metadata is quite straightforward:
app.activeDocument.metadataPreferences.author = stringOfAuthors;
Does anybody have an idea of how to prevent the quoted form of authors in the corresponding metadata field?
Thanks,
Tobias
You can try createContainerItem() and setProperty(). Here is an example.
Roland
Thank you very much for your inspiring work, Roland!
This was the right way to go (although it’s a rocky one ...)! I hope you don’t mind, that I use some of your code lines in this threat ...
For people who are stumbling over this thread:
InDesign’s easy access to the "author" metadata field ("metadataPreferences.author") respects only (and consequently) one author for an InDesign document. If there is a comma or a semicolon inside the author String, it treats this as one author and qoutes it (as
...Copy link to clipboard
Copied
The quotes are added because of the commas and/or semicolons. With any other character (exlamation point, dot, hyphen, ampersand, etc.) the quotes don't appear. Compare with how commas and semicolons (and quotes) are handled in spreadsheets. There's nothing you can do about it.
Copy link to clipboard
Copied
Thanks for your feedback, Peter. But then, in my eyes, this is a bug. Authors in PDF description should be separated by comma or semicolon, every PDF parser will use those as delimiter. Then I’ll post a bug report on uservoice.
Thanks,
Tobias
Copy link to clipboard
Copied
For everyone, who wants to vote:
Copy link to clipboard
Copied
I have no idea if it's a bug or not, but the engineers do, and if not a bug, it will be dismissed with two simple words, "as designed."
Copy link to clipboard
Copied
I can enter comma or semicolon separated authors in the GUI. So it’s worth a try!
Copy link to clipboard
Copied
You can try createContainerItem() and setProperty(). Here is an example.
Roland
Copy link to clipboard
Copied
Thank you very much for your inspiring work, Roland!
This was the right way to go (although it’s a rocky one ...)! I hope you don’t mind, that I use some of your code lines in this threat ...
For people who are stumbling over this thread:
InDesign’s easy access to the "author" metadata field ("metadataPreferences.author") respects only (and consequently) one author for an InDesign document. If there is a comma or a semicolon inside the author String, it treats this as one author and qoutes it (as mentioned in the starting post).
This respects the possibility to insert authors with "[last name], [first name]", as in "Gibson, William" – either separated by comma or semicolon.
To insert multiple author names correctly, we have to use the XMP methods.
Here is a piece of code, which allows to correctly insert multiple authors into the XMP metadata field "author":
const destinationNameSpace = "http://purl.org/dc/elements/1.1/";
const destinationName = "dc:creator";
const containerType = "SEQ";
var activeDoc = app.documents.item(0);
var metadataPrefs = activeDoc.metadataPreferences;
var numberOfContainerItems = metadataPrefs.countContainer(destinationNameSpace, destinationName);
var newContainerItems = ["William Gibson", "Dorothy Sayers"]
/* Check if container exists */
if (numberOfContainerItems === 0) {
/* Create new container */
metadataPrefs.createContainerItem(destinationNameSpace, destinationName, 0, ContainerType[containerType]);
}
/* Empty existing container */
for (var n = numberOfContainerItems; n > 0; n -= 1) {
metadataPrefs.setProperty(destinationNameSpace, destinationName + "[" + n + "]", "");
}
/* Fill containerItems into container */
for (var i = 0; i < newContainerItems.length; i += 1) {
var objectItem = newContainerItems[i];
var itemIndex = i + 1;
var itemPath = destinationName + "[" + itemIndex + "]";
metadataPrefs.setProperty(destinationNameSpace, itemPath, objectItem);
}
Please note, that this is just a proof of concept ignoring error possibilities. For a better implemenation with error checking, analyse Rolands code carefully.
I found a very informative resource on "XMP metadata in InDesign scripting" in some of tomaxxi’s blog posts:
https://indisnip.wordpress.com/?s=xmp
Especially this one:
https://indisnip.wordpress.com/2010/09/07/storing-custom-data-into-indesign-file-xmp/
Thanks a lot,
Tobias
Find more inspiration, events, and resources on the new Adobe Community
Explore Now