Skip to main content
GitHub

Getting notes out of Apple Notes on Mac: a needless odyssey

2024-09-27 in Posts

I was surprised to find that there isn’t a built-in way to export more than a single note at a time from Apple’s Notes app on MacOS, but thought that I’d uncovered an opportunity to write a fun little blog post about using Livebook to extract notes from the app’s SQLite database.

I was incorrect.

TL;DR

Some highlights of my ensuing learnings:

  1. Apple stores its notes as protobufs and the format just keeps getting more complicated over time. I sure didn’t want to reverse engineer that (not for my crappy notes, anyway), but Jon Baumann has been keeping up with the changes for years, and maintains a Ruby program, Apple Cloud Notes Parser, based on this knowledge. This program seems to have handled my notes flawlessly, complete with PNGs, JPEGs, and PDFs variously embedded and attached. It thereby wins, by a wide margin, the Apple Notes export tool shootout that I never intended to hold.

  2. Obsidian has an import tool based on Baumann’s work. It didn’t find all the images in my notes. I’ve been too invested in TiddlyWiki to spend much time with Obsidian, but I have to take a moment to nod at them for keeping notes in human-readable .md files.

  3. AppleScript is a hoot (and a time warp). The Notes app has some rudimentary support for it; if your notes don’t have attachments, AppleScript could be just the tool for the job. More generally: if the app you’re working with doesn’t provide a lot of properties for AppleScript to work with, you can end up leaning on simulated UI interactions. While a script is running, your real UI interactions can interact with these interactions. Scripts in the wild are peppered with delay commands to leave time for the previous command to complete. Wild is right.

The drip feed

Here’s how I arrived at the above, more or less:

  1. Apple Notes has a menu item to export one (1) note at a time as PDF.
  2. Apple Notes are not stored in text files; they’re stored in a SQLite database.
  3. For simple-ish notes, the “Notes Exporter” app on the Mac app store may be the low-effort solution. I didn’t confirm.
  4. There are some AppleScript scripts floating around that sort of or almost work on notes in 2024. (I’m sure it’s not worth learning AppleScript just for this job.) Scripts I came across: [Bear.app], [Alex Chan]
  5. Someone had 12k notes and they got ahold of them by requesting their iCloud data from Apple – apparently this also works more or less OK, but perhaps not perfectly in 2024? (My notes aren’t in iCloud.)
  6. Apple Notes body data is gzipped. [Ciofeca Forensics 2017]
  7. Apple Notes bodies, gunzipped, are stored as protobufs and reconstituting the original content is very involved, particularly if there’s more than text inside them. (AppleScript looks less daunting again, by comparison.) [Ciofeca 2020 1], [Ciofeca 2020 2], [Ciofeca 2020 3]
  8. Apple Notes is not very AppleScriptable. You can get, like, the body text with images (if they’re embedded), and references to attachments, but not, it would appear, where in the note the attachments might have been displayed. To render multiple whole notes with attachments, you’re into simulating UI interactions. Wild.
  9. Obsidian has an import tool that actually works. Mostly. [Obsidian.md]
  10. I seem to have absorbed more AppleScript than I ever planned to. I bet I could just quickly…
  11. OK, that took a little longer because I decided to learn to work with dates in AppleScript. NP I’m sure that’ll be super useful in the future. :P Aside from a bug in the PDF export function of Notes that can chop off part of an image (nothing to do with automation), scripting the menu interactions to export each note to PDF seems to work OK. Here’s my script that does that. Look at it for fun, and choose some other solution.
  12. Oh, look: Jon Baumann, who wrote all those Ciofeca Forensics blog posts reverse engineering the protobufs, has a Ruby program to extract the contents of notes. And it worked perfectly on my notes, including attachments, so far as I have discovered.

For shame

My actual existing notes are, at this point, the least interesting thing about this for me.

Normally I feel pretty good about my problem-solving skills and my web-searching muscle memory, but a clean solution to my specific practical problem has existed for years and I almost didn’t find it.

If I’d been a little more knowledgeable, and/or a little more open-minded, I might have avoided the ruts I ended up following. For one, it was folly to think that an app that wants me to sync data between my devices with iCloud would give any (sympathetic) consideration to data portability, but I let myself be surprised, repeatedly, by the different facets of this.

More generally, if I want to be more efficient, I have to apply a better test for unconscious incompetence before I dive in.

I did ask ChatGPT 4o and Claude 3.5 Sonnet to help me find a way to get at my notes. They got faked out by the same surfeit of out-of-date or partial solutions that I did, and probably gave me false confidence that I had surveyed the possibilities well enough to plow ahead with implementation. Acknowledged: there’s a chance that my prompting left something to be desired.

The chatbots were helpful with figuring out how to do things in AppleScript. Even if doing things in AppleScript was actually a diversion from my ultimate goal. I love learning how to do things! But I could have learned something different in that time.

Addendum: the journey continues

Here’s something that gets me: after drafting this post, I happened to listen to the 10 September episode of the Software Misadventures podcast, featuring Simon Willison. Near the end, Simon mentions that—in early 2023—he used ChatGPT to help write an AppleScript to export his Apple Notes(!) He wrapped it up in Python, and if the body property that Notes makes available to AppleScript is enough to cover your notes’ content, this looks like a lovely, polished, well-documented tool. You can even install it with pip. None of my rabbit-holing took me to this information, nor explicitly to Steve Dunham’s work on understanding and converting Apple’s Notes format.

So, like, one weirdly specific takeaway for me: for a non-trivial subset of the things I’m interested in, one of the first research steps should be check to see if Simon Willison has written about it already.