Hacker News new | ask | show | jobs
by simonw 1183 days ago
I wrote a similar tool in Python a few weeks ago, which uses AppleScript to liberate the data and saves it to a SQLite database: https://datasette.io/tools/apple-notes-to-sqlite

I didn't actually know AppleScript before writing this tool... but it turned out ChatGPT knew it well enough to unblock me and provide me with exactly the code I needed to build the rest of the project! https://til.simonwillison.net/gpt3/chatgpt-applescript

Apple Notes Liberator creates a copy of the SQLite database and then runs queries against that directly to extract the data.

I chose not to do that (despite being all-in on SQLite for everything) because I worry about future changes to the software baking my script - I figured the AppleScript interface was less likely to have breaking changes in the future.

7 comments

From your article on how you wrote that:

> I've been stubbornly refusing to learn AppleScript for nearly twenty years at this point. Thanks to ChatGPT I can continue not to learn it, but I can now use it to solve problems

The Apple scripting stuff can also use JavaScript. It might be better to continue not to learn in JavaScript instead of AppleScript, if ChatGPT is as adept at Apple scripting in JavaScript as it seems to be in AppleScript.

That way if you want to tweak what ChatGPT gives you it will probably be easier. With AppleScript both interacting with other things and control flow or computation can be weird and confusing. With JavaScript at least the control flow and computation will likely be more normal.

Huh, that's a great tip! ChatGPT knew how to convert my AppleScript to the equivalent JavaScript and showed me how to run it too: https://gist.github.com/simonw/86c2153b7882747122f1e3d501260...

Added a section about this to my TIL: https://til.simonwillison.net/gpt3/chatgpt-applescript#user-...

I was trying to do a thing with AppleScript, and the barriers I ran into were not with the language, but with discovery of the APIs that Apple surfaces to the end user. In that regard, you’re better off with AppleScript. I can’t believe just how bad the AppleScript documentation is, but the js documentation is even worse; using js is just using AppleScript but with an additional layer of indirection that doesn’t provide any productivity gain.
There's an O'Reilly AppleScript book that's pretty good.

The problem I always had with AppleScript is that it wasn't clear when I was writing AppleScript and when I was talking to an application's OSA dictionary (its "terminology" as Apple calls it in OSA).

Once I switched to Appscript (https://appscript.sourceforge.io/), that confusion went away. Of course I haven't used that in years since it's no longer supported and today I'd use JavaScript.

The issue though is that each application's terminology is isn't really documented. You can usually figure it out using Script Editor, but not always.

Some of this is documented here:

https://developer.apple.com/library/archive/documentation/La...

IggleSniggle expresses it well. As ugly as the AppleScript expressions are, they force you to write in a way that's sympathetic to the API, so, in addition to returning errors at all in more cases, they're easier to diagnose or minimize.

https://gist.github.com/mcint/561f72e6baa3e5c68c2577b04dad78...

I've linked some of my scripts, bash calling applescript, that I use extensively to export tabs from browsers.

I did a bit of AppleScript recently (scripted changing between draw and erase in zoom annotations from the buttons on my tablet pen). In my reading I got the impression that not everything is implemented in js so you might get stuck.
"Unblock" is the perfect term for the effect of all these GPT things on me. Thank you for coining that!

Recently I wanted to have something like that but for Safari Reading list. The main difference is I tried to find a solution not for one time liberation, but for continuous 2-way exchange with some web service. It appears you HAVE to run everything locally for that. I like "privacy", but I like having options even more.

By the way it was ChatGPT that helped me to remove this several month old item from my TODO list.

I loved your post about the pelican! https://simonwillison.net/2020/May/21/dogsheep-photos/
Here is a Python library that can also create notes: https://github.com/RhetTbull/macnotesapp

It is also based on Action Script commands. I haven't played with it much yet, but it's on my TODO list (to add automatic headings for every day + archive DONE tasks automatically).

Interesting. I was curious and wanted to achieve something similar with voice memos. I used the prompt "Write applescript to loop through all of my Apple Voice Memos" and the code it produced couldn't run in applescript.
I just tried that prompt against GPT-4 and got "Note that the Voice Memos app does not have an AppleScript dictionary, so the script will use UI Scripting to interact with the app" followed by a very complicated recipe.
Nice tool! Just tried it, works great. Interesting that Applescript exports the images as Base64, or does Apple notes store them like that as well? Maybe converting them to binary when exporting would save some space.
A bit out of context, but did you know you can actually write OSA scripts using JS? In Script Editor there’s a menu where you can change the language.