Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

InDesign insert authors into document's metadata without quotes

Engaged ,
Dec 11, 2022 Dec 11, 2022

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:

Bildschirmfoto 2022-12-12 um 07.53.43.png

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

TOPICS
Scripting
1.3K
Translate
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 2 Correct answers

Contributor , Dec 13, 2022 Dec 13, 2022

You can try createContainerItem() and setProperty()Here is an example.

Roland

Translate
Engaged , Dec 14, 2022 Dec 14, 2022

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

...
Translate
Community Expert ,
Dec 12, 2022 Dec 12, 2022

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.

Translate
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
Engaged ,
Dec 12, 2022 Dec 12, 2022

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

Translate
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
Engaged ,
Dec 12, 2022 Dec 12, 2022
Translate
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
Community Expert ,
Dec 12, 2022 Dec 12, 2022

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

Translate
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
Engaged ,
Dec 12, 2022 Dec 12, 2022

I can enter comma or semicolon separated authors in the GUI. So it’s worth a try!

Translate
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
Contributor ,
Dec 13, 2022 Dec 13, 2022

You can try createContainerItem() and setProperty()Here is an example.

Roland

Translate
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
Engaged ,
Dec 14, 2022 Dec 14, 2022
LATEST

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

Translate
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