AppleScript: image attachments to a Note mysteriously appear twice

I thought I might have found - thanks to your excellent idea and discovery - a solution. But sadly it does not work optimally for my use case: I am using Pandoc for converting Obsidian Markdown notes into Apple Notes.

I think (with Shortcut) I can’t pass a “note” as an input, to have a series of files to be attached to it.
I can only “create” from scratch a new note.

Just leaving this here in case anyone stumbles across this thread. I found some weird behavior while writing a command line interface to notes related to attachments. This is what Claude Code and I found out:

Manual UI Attachments

  • Embedded as base64 data URIs: <img src="data:image/png;base64,...">
  • Fully visible in Notes app
  • Self-contained in HTML (100KB+ for images)
  • No duplicate issues

AppleScript on IMAP

  • Creates <object type="application/x-apple-msg-attachment" data="cid:...">
  • Images MAY display in Notes app (version dependent)
  • No duplicate bug
  • All file types supported

AppleScript on “On My Mac”

  • No HTML integration (no tags added)
  • Attachments invisible in UI and plain text has two unicode (U+FFFC) character which is the Object Replacement Character
  • Duplicate bug: Each attachment appears twice (same ID)- Workaround available: delete attachment 2 of note

What You Cannot Do

  • :x: Insert <img> tags with base64 data URIs (stripped by sanitizer)
  • :x: Preserve existing base64 images when copying note bodies
  • :x: Use CSS background-image with data URIs
  • :x: Insert SVG, iframe, or complex HTML