Read / Write to text files

This pair of actions will write Drafts to text files, then allow you to update the Drafts later with the edited contents of the text files.

It works like this:

The Write Files action will ask you which workspace you want to choose, then which filter you want (e.g., inbox, flagged, all, archive, trash), then what you want to use for the file extension. It will then write the drafts to text files in the following folder structure in iCloud Drive “Drafts/Files/[Workspace Name]/[Filter name]/file.extension”

It will also create a JSON in iCloud drive (“Drafts/JSON/files.json”). This file will contain the names of the drafts and their UUIDs, as well as the file extension used.

The Read Files action will read this JSON file, provide a prompt allowing you to choose which workspace and filter you want to overwrite with the contents of the text files.

Notes:

  • The Write action will assign “Draft 0”, “Draft 1”, etc. file names to any Drafts without content in the first line. These names won’t be added to the Draft itself.
  • Each time you “write” Drafts, the JSON for that workspace and filter is overwritten. The text files will also be overwritten. However, if you delete a Draft, any text files you made of that Draft previously won’t be deleted or removed.
  • If you fail to choose an option in any of the menus, there will be a script error instead of a nice error message. I’m not sure how to add the logic to make a nicer error message.