Script for Day One

I ended up doing something like that. It’s not packaged as a Plug-In, just a few KM macros and some script elements.

My solution is here: HookPlugins/Day One at master · kraigparkinson/HookPlugins · GitHub

I’ve implemented Get Name, Get Address, and New Item.

The ‘Get Name’ AppleScript invokes the Get Name macro, which acts as a UI driver to get to the JSON export of the entry, opens it in TextEdit (because there’s no copy to clipboard option), reads the contents, finds the first line of the text as the title, closes the TextEdit window (but doesn’t quit it), and returns the name. This uses the JSON Helper library.

The ‘Get Address’ AppleScript invokes the Get Address macro, which acts as a UI driver to get to the Copy Entry URL menu item and returns it.

Both of the above rely on a third macro, Trigger Context Menu, that at the moment only works on the main window. (With a little work, I could get it to work on dedicated entry windows, but that’s not a priority for the moment.) It’s the one that gets the context menu to pop up in the first place to do the rest of the UI driving.

I tried to do both of the above with just AppleScript, but the context menu wouldn’t respond to any actions I threw at it. If someone figures that out, I’d appreciate it a pull request or a comment.

Finally, the New Item script will go ahead and create an entry by calling a shell script to invoke the Day One 2.0 CLI and then it will parse the response via RegEx to get the UUID using the Text script library. Then it converts it into a URL. The Day One 2.0 CLI needs to be installed per the instructions in the link, and the Text script needs to be installed in ~/Library/Script Libraries or /Library/Script Libraries as usual.

No warranty on this, and if it breaks something for you, please don’t hold me responsible. But I’ve been using it for a couple of days now, and other than it being slow and cringeworthy, it does the trick for me.

1 Like