UXP: Cannot clear metadataPreferences

,

Assigning an empty string to a string property within Document.metadataPreferences (such as copyrightNotice) fails to clear it. The assignment is silently ignored, and the existing string remains unchanged. You can change it to any value, but not an empty-ish string.

Example from UXP Dev Tools Console):

> doc.metadataPreferences["copyrightNotice"] = "TEST"
"TEST"
> doc.metadataPreferences["copyrightNotice"] = "" # trying to set empty string
""
> doc.metadataPreferences["copyrightNotice"]
"TEST" # should be ''
> doc.metadataPreferences["copyrightNotice"] = "TEST UPDATE"
"TEST UPDATE" 
> doc.metadataPreferences["copyrightNotice"]
"TEST UPDATE" # updating the string worked
> doc.metadataPreferences["copyrightNotice"] = '' # trying single quote empty string
""
> doc.metadataPreferences["copyrightNotice"]
"TEST UPDATE" # the previous state remained, field wasn't emptied
> doc.metadataPreferences["copyrightNotice"] = " " # trying one space as "empty-ish" string
" "
> doc.metadataPreferences["copyrightNotice"]
"TEST UPDATE" # did not work
> doc.metadataPreferences["copyrightNotice"] = "\n" # trying a line break as another whitespace character
"\n"
> doc.metadataPreferences["copyrightNotice"]
"\n" # changing to a line break worked, seems to not be considered empty

Expected Behavior:
Assigning an empty string should clear the metadata property.

Actual Behavior:
The empty string assignment is silently ignored. The property retains its previously set value.

Additional Context:

  • Attempting to clear the property with null or undefined is not possible, as it throws a strict type error: Uncaught Error: Invalid value for property setup 'copyrightNotice'. Expected String, but received nothing.
  • The issue occurs both within UXP plugins and directly in the UXP JS Console.`

Environment:

  • Application: Adobe InDesign 21.2
  • API: UXP Scripting

Hi Roman,

take a look at the setProperty method for MetadataPreferences.

This should allow you to remove the entire container:

XMP

...
<dc:rights>
   <rdf:Alt>
       <rdf:li xml:lang="x-default">Copyright</rdf:li>
   </rdf:Alt>
</dc:rights>
...

Code

app.activeDocument.metadataPreferences.setProperty("http://purl.org/dc/elements/1.1/", "dc:rights", "")

Adobe Bridge also has a deleteProperty method, but InDesign does not.

Roland

1 Like

Thanks Roland, thatโ€™s a good workaround!

1 Like