Automation for journal writing

I have started with Scrivener for journaling and so far I am happy with my setup. The structure is very standard (YYYY/MM/DD Weekday).

I am generating every morning some rtf files (quotes, news feed, references to changed files) with a python script.

The next step is fully manual - importing into the right folder inside scrivener and setting some metadata).

Is there a way to automate the last step as well?

Thanks for any help.
(I am on macos)

1 Like

Do you know about the External Folder syncing feature? It allows you to create and edit files outside Scrivener and sync them in and out automatically on project open/close, or manually.

So, have your files created by your program inside the synced folder and they will be imported when you next open the project, or sync.

There are quite a few options,mso have a look at the manual entry before you start (sorry, I’m not at my Mac, so can’t give more details right now, but it’s a flexible process which sounds like it will help you,)

[Edit: Back on the Mac]

The External Folder sync commands are at File > Sync > With external folder…. This will open a dialogue with several options to allow you to set it up:

You can do some quite sophisticated things with this, as you can see from the options, and there are a couple of caveats, so do look at the relevant section in the manual before experimenting: it’s at Section 14.3 Synchronised Folders.

HTH.

3 Likes

Here is a discussion on methods of creating new notes in projects from external sources. The method described above, of using the sync folder feature to set up an “inbox” is gone over in detail, there, as well as other approaches such as using the scratch pad feature. The only update I would have for this older post is that neither of those Mac tools I mentioned further on down, as “front ends” to the sync folder, are maintained these days. More people are using Scrivener Sync-folder + Obsidian, and Markdown files for this kind of task.

But if you do want to continue down the scripting path, it can be rewarding to do so as the above mechanisms are limited, and do have their awkward corners here and there.

The main downside to scripting against the project itself is a need to close it and reopen it, which neither of the above methods have an issue with. But that problem can be dodged by making use of the Mobile folder, which the iOS version creates and uses to insert and modify data into an open project, back on the Mac/PC.[1]

The hardest part about that will be the binder.mob file, the rest is so dirt simple it’s barely even scripting. Here is an example project, started from Blank, that has had one single file added to it on the iPhone:

simple_mobile_folder_example.tar.gz (11.4 KB)

The “Mobile” folder created from this action looks like this:

simple_mobile_folder_example.scriv
├── Mobile
│   ├── binder.mob
│   ├── Data
│   │   ├── 35ABC720-C93A-4FA3-AB21-8FC0EBEE8502.checksums
│   │   └── A8A32240-0438-48A3-BAB3-DF0D13D3A61E
│   │       └── content.rtf
│   ├── search.indexes
│   ├── structure.cache
│   └── writing.history

You can omit everything at the top level save for the ‘binder.mob’ file, you do need to examine that and see how the inserted content.rtf file is mapped. The checksums file can also be omitted, that is only used by the iOS version itself to ensure data integrity between uses.

As for the binder.mob file, you basically want to diff it with the .scrivx to see where they differ. You want to copy the whole Binder tree from the .scrivx into it, and then make your insertion to that. You can then copy the LabelSettings, StatusSettings and ProjectTargets verbatim. I haven’t tested leaving those out, as changes to those are meant to sync, naturally (otherwise we wouldn’t include them in the .mob file). Overall, not that difficult or different from injecting something into the .scrivx XML.

The most difficult part about this (either editing the main project or using Mobile) in fact is generating RTF files, and it sounds like you have that part under control already. For anyone else coming along, if you don’t have a good library in your scripting language for it, Pandoc can generate clean and simple RTF files, and you can specify a custom header too, which can mean adopting the project default formatting (which can be extracted from the project’s settings).


  1. Well, technically it will still reload the project, but it’s the software doing it for you as part of the syncing process rather than you have to remember to close it, run your script, then reload it (or add more code for understanding and working with the lock files to avoid mistakes). ↩︎

3 Likes

Thanks @brookter and @AmberV I will look into your suggestions. Looks like I can achieve what I want and need to see which of the solutions works better with my workflow.

In regard to generating the rtf files with python, I am using is a special pandoc (pypandoc) library.

Thanks for your help.

2 Likes