Skip to main content
Inspiring
December 12, 2022
Answered

InDesign insert authors into document's metadata without quotes

  • December 12, 2022
  • 2 replies
  • 1361 views

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

This topic has been closed for replies.
Correct answer tobias.wantzen

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

2 replies

Inspiring
December 13, 2022

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

Roland

tobias.wantzenAuthorCorrect answer
Inspiring
December 15, 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 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

Peter Kahrel
Community Expert
Community Expert
December 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.

Inspiring
December 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