Accessing the 'Display Name' of an attached or linked image

I’m writing an export plugin and wanted to be able reference exported attachments from the exported text using Display Name as part of the reference, for example:

! [My latest picture] (photo-2021-03-08.jpg)

I can get the filename from the FileWrapper within an AttributeRun, but haven’t managed to discover where the text of the Display Name is held. The run text is blank, and the attachment Text object doesn’t seem to have it either.

In the case of linked images, I can get the filename from the run style link string, but the Display Name seems a bit hit and miss (mostly miss).

This is my first plugin so I hope I didn’t miss something obvious.

Could you post a minimal working example ?

function TestCode()
{
	rootItem.descendants.forEach(function(item)
	{
		var textObj = item.valueForColumn(document.outline.outlineColumn)

		textObj.attributeRuns.forEach(function(run)
		{
			run.style.locallyDefinedAttributes.forEach(function(attribute)
			{
				if(attribute.key == "text-attachment")
				{
					if(run.fileWrapper) // embedded image, want to use Display name rather than preferredFilename
					{
						console.log("![" + run.fileWrapper.preferredFilename + "](" + run.fileWrapper.preferredFilename + ")")
					}
					else // referenced image
					{
						// run.string usually blank
						console.log("![" + run.string + "](" + run.style.link.string + ")")
					}
				}
			})
		})
	})
}

Just looked into this. I pasted a file named url1.jpg and this are the properties of its FileWrapper.

[object FileWrapper: file, 124887 bytes] {children: [], contents: [object Data], destination: null, filename: "url.jpg", preferredFilename: "url.jpg", type: [object FileWrapper.Type: File]}

Where is the “Display Name” of your image file held ? Is it in the metadata ?

The Display Name is part of the embed, as shown here:

Screenshot 2021-03-08 at 18.33.16

This popup is also available for linked images, and I’m hoping I can get to the Display Name in those circumstances too.

I see. Apparently, that specific property is not exposed in OmniJS API. However, it seems to appear when decompressing .outline file inside contents.xml.

<item id="aXfXEkdTd8_" rank="0001">
    <checkbox>unchecked</checkbox>
    <entry/>
    <text>
    <p>
        <run>
        <lit><cell refid="att0" expanded="yes" name="Woodland Operation in Hampshire"/></lit>
        </run>
        <run>
        <lit>Hello World</lit>
        </run>
    </p>
    </text>
    <entry/>
    <entry/>
</item>

Thanks for checking. I wondered about the internal format as a way of guessing it’s property name.