Note Metadata in Text Bundles

Bear is a wonderful notes editor, and I’ve started using it to power a little static site with some of my thoughts.

I’m still iterating on the best approach to get my content out of Bear. My first attempt read notes from Bear’s SQLite database directly, but more recently I’ve been looking into using Bear’s own export features.

Bear taught me about the TextBundle format, which seems like a good fit for this use case. The format has room for custom app metadata (See the section The Meta Data File in the link above) where additional attributes can be exported alongside a note.

Right now Bear’s text bundle info.json looks like this:

{
  "transient" : false,
  "version" : 2,
  "creatorIdentifier" : "net.shinyfrog.bear",
  "net.shinyfrog.bear" : {
    "version" : "2.0",
    "bear-note-unique-identifier" : "FA5C2D56-CB93-4EAE-B4EB-25B98BC36B22"
  },
  "type" : "net.daringfireball.markdown"
}

It would be awesome if this was enriched with note-specific metadata that Bear knows about, e.g. something like this:

{
  "transient" : false,
  "version" : 2,
  "creatorIdentifier" : "net.shinyfrog.bear",
  "net.shinyfrog.bear" : {
    "version" : "3.0",
    "bear-note-unique-identifier" : "FA5C2D56-CB93-4EAE-B4EB-25B98BC36B22",
    "title": "Trying something new.",
    "tags": ["#pub", "#til"],
    "createdDate": "2024-12-08T13:01",
    "modifiedDate": "2024-12-08T14:02",
  },
  "type" : "net.daringfireball.markdown"
}

If this feature request is taken up, my intuition is that the most valuable additions would be attributes that are not able to be parsed out of the Markdown file, such as creation and modification dates.

Having the title and tags and title in the metadata would also be very helpful in minimizing downstream work, though, since extracting them correctly otherwise requires re-parsing the note as Markdown and extracting the tags using a regular expression that matches Bear’s multi-word tags.

Thank you for your consideration and for the great app.

1 Like

If you are mainly interested in modification/creation dates I suggest using Bear’s backups. The backups are compressed folders containing textbundles with extra information. Doesn’t report the tags but the title should be the name of the file.

1 Like

Yes, the dates are the primary thing, since the rest can be parsed out of the Markdown content. The data in your screenshot is exactly what I’m looking for. Thank you!

Out of curiosity, do you know if there’s a way to “back up” a only a subset of my notes?

(I noticed it takes a few seconds, and exporting the full set of notes means that I have to read through and parse all of the notes to figure out which ones to publish.)

No, this is not possible as the backup to works had to be performed on the whole library.

Any chance you can read the file’s metadata on the file system? I remembered the note dates can be mirrored on the exported file.

1 Like

That’s a good thought. If I could read the dates from a regular note that’s exported as a text bundle, then I can export just the notes that I need.

May I ask how you got that text bundle? I just tried re-exporting individual notes using an Apple Shortcut (same one as above), and it looks like those text bundles have their created dates set to the wrong time.

For example, here’s the metadata for one of my notes in Bear:

And here’s the metadata for the same note as exported using the Apple Shortcut from above:

For the other notes, both the created and modified dates show the same time of 10:09. My most recent edit to all of these was to remove the explicit frontmatter I had added earlier; though I don’t see why that would explain anything.

I also found a note whose created time is after its modified time:

Edit 2: I re-exported the first note again and now it shows as both created and edited at 10:52 today:

Would there be an issue with adding the date metadata to the regular export? Then I could export using the Shortcut, and get the metadata from the info.json file.

I used the in-app export functionality of Bear, not the Shortcuts. I suspect Shortcuts alters the dates because has to copy the file.
You can set the file dates from Shortcuts using the script action. You can use the <note object>.Creation Date e Modification Date.

It’s a quite niche request but we can consider it in the future.

2 Likes