Bulk exporting multiple drafts as individual text files

Hello Everyone! How can I export multiple drafts to individual text files to index in an app such as Obsidian or Devonthink? When I select multiple drafts and run the export action, it puts them all into a single text file. Thanks!

You can select the drafts and use the run action option from the operations selection to run an action against each selected draft. The delivered as standard “Save to Files” action will then allow you to save each draft to a file. However, you will be prompted for the save each time.

You could create an action that exports to a default location such as this one:

But I think is going to save all drafts. Assuming that is the case, you could modify the action to use a different query to identify which drafts to export. For example using a tag. You could then use another action to batch add the tag to the drafts you want to export (using the run action against selected drafts as above). Your modified action could also remove the export tag from a draft after a successful export.

Hope that helps.

Thanks for your reply. I’m not very good at modifying Draft actions but I did find a solution to my problem. I exported my files in JSON format to the Bear app which converted them to text files. I then exported the text files out of the Bear app to a Finder folder.

Now, it would be best to add this feature to the Drafts App :wink:

Such work-arounds are difficult for many and the App should be easy to us, right?

I tried this, but only get a series of pop-ups like this:

I tried again after creating a “Dafts_md” folder in top of iCloud drive, but that did not change nothing.

I tried this too, but am unsure about the method to use.

Import Notes?
This does not seem to allow import from a Drafts backup.

Restore Backup?
This requires the file to have ending “bear2bk” as it seems, but still, I only get this message:

IMG_0890

Of course, I am connected to the internet - also the file is sitting locally in “On my iPad” document provider!

Not necessarily since there is no standard approach to export. E.g. with/without meta data, format, etc. You could export as JSON as Drafts tends to do, but that isn’t suitable for many users - particularly those who might expect a “standard” solution to be simpler.

I don’t think batch running actions is too difficult. Select drafts, run action, done. It just needs to be the right sort of action as some actions are built for single draft processing.

My best guess would have been a non-existence issue. You note you tried without it and then in the root level of iCloud Drive. However, I think this action is set up to write to the Drafts folder in iCloud Drive and so the Drafts_md (*which doesn’t actually seem to quite line up with the original author’s description, which suggests it will write directly to the Drafts folder.


However, you are referencing back and posting on a topic that is an almost a couple of years old, and Drafts gets regular and fairly frequent updates in terms of its capabilities. I’ve whipped up a quick action that will let you do a basic export using some functionality that has been added since this discussion - functionality that allows for a somewhat simpler process in my opinion.

  • The action contains a template tag step to specify the file extension (I have set as “md” as a default but you can modify it).
  • The action will always write plain text to the file.
  • The content of the file is set to be the ‘body’ of the draft (line 2+).
  • The base file name (without extension) is the ‘safe title’ of the draft (line 1 without any text that would be invalid in a file name).
  • The action prompts you to specify an export location (set as the Export_To folder bookmark in Drafts. The files will be exported to that location.

Now, some of those things you might want to change such as prompting for a title, or exporting the whole content of the draft rather than just the body … which comes back to my earlier point of people often wanting something a little different. But this action then gives you a starting point, and the code in it is pretty concise, so there isn’t a huge amount to get your head around, and you can always ask a question or two back here to clarify things.

1 Like

Ohhhhh, fantastic :hugs:
Did not test yet, but great many thanks!

What would I need to change to get the first line also into the export?

While the first line is a good default for a filename, it still is part of the file and not a good candidate to just remove from the exported file :sweat_smile::sweat_smile:

Change [[body]] I the script to [[draft]].

It is a common option for the filename, which is exactly why the safe_title template tag exists. Sequence numbers, creation & modifies timestamp, combinations with geo location, etc. also make good file names in different circumstances.

Since the file name is already data in the file many, but not all uses then find it redundant to I Claude I the content.

This all just comes back around to people wanting different things and a one size fits all export to file option simply isn’t possible - people have different needs for different circumstances, and Drafts is customisable enough to help you define an option for doing pretty much all of them.

1 Like

First, thanks for the required change!
Going to test.

Second, I totally understand what you write about specific wishes or needs for an export, but those are really individual wishes!

A basic export just needs to export each note as a file - and for this, the first line as filename is a sane default, probably extended with a timestamp ( creation or modification time seem valid).
And that’s it already!

And ideally, you could import such exported files again and have exactly the same result. Transparent exports and imports, usable as backup and for use together with other Apps.

The bulk of people would be happy with this! At least more than with “2124 files as one giant file, even without a seperator” … like “cat * > all.txt” i a Unix shell.

This type of export (the regular App export) is not usable in most circumstances, as it destroys the separation of text into drafts / notes / files

It would only be usable, when your drafts are just chapters of a big article and this export represents having the chapters all in one file. Kind of publishing lots of notes into one file.
But that will rarely be the case :sweat_smile::wink:

P.S Somehow, my replies are never shown as replies first - I need to reply again to see it marked as a reply and then delete my first (bad) reply

Any idea how I could get my modified action into Drafts?!?
Sharing just opens it as text.

Drafts contain more than just content. There’s a whole host of meta data as well. You could create a new draft from a simple export as you describe, but it would not be the “full” draft per se.

As noted on another thread, there are assumptions about suitability, and could it not be said that your definition for a basic export is the wish of an individual?

Based on the things I have read on this forum (I’ve probably read most of the posts), seen in YouTube videos, and read on people’s own blogs, I would think the chances would be high that there would be a more than a handful of variations on what people would expect to be included in a standard export. It would make for an interesting poll, but there are that many possible variations, I also think there is a good chance it would exceed the forum’s polling function’s limits :laughing:

Assuming you modified your action in Drafts, it is already there.

Sharing an action externally is best done by sharing to the directory - you can do so unlisted.

I cannot edit the action within Drafts - I am a basic user nowadays :sweat_smile:

Going to watch this video …

But maybe this already shows how useful a basic export could be :hugs:
I will write later about this!

As this topic is about exports, I am replying here, not in the “Select all” topic:

I totally understand what you wrote about individual ideas and wishes about an export!

But for a “basic” export (and import) that would fulfil the needs of most, the following would sure be enough:

Getting a selection of drafts out of Draft in a way that they could be restored in Drafts again, at a later time, probably with changed content.

So, the naming in Drafts would need to be the same and the order in which the files will be shown, which is the last modification time (at least I cannot remember that I changed this)

For this, you would just export like your actions does, with the modifcation to export the whole text and not drop the first line - and add the modification time to the files.

Doing this, you could then re-import those files and add them to the Drafts database like they were before - by just reading the modification time from the filename (which could have been changed) and set this timestamp again in the database.

Finish.

Most other wishes (if not based on access- or creation-times) could be done after export. Maybe it would be best to be able to choose which of the timestamp should be used, or maybe even allow very long filenames and add all three timestamps to the filenames.

Then, you could easily get a selections of notes our of Drafts and later back into Drafts. The export and import from Bear seems to work like this - and this is a very very useful basic export!

And it is way better than exporting just any and all notes as a concatenation in one file - who could use this?!?

Example code for import:

export(file, draft.firstline()+“_”+draft.mtime())

Example code for import:

import(draft,draft.mtime=(file.name.mtime()))

Something like this …

As fantastic as your “Export Selected Drafts” is, I cannot use it - it removes the first line, which would destroy most of my documents.

This line sometimes is just a heading, but at other times normal content.

I modified it to use “draft” instead of “body” but I cannot find a way to use it, as I am not a Pro user - and see no way to do this.

So, without a kind soul that uploads the modified version to the actions website, I am stuck and cannot export - that about this being easy :cry: :cry: :cry:

This forum is for helping users get the most out of Drafts, and the users here do a great job of sharing information and providing assistance.

I ask you to recognize that people providing this assistance are not doing so to do work for you, and customize the app so that you can avoid paying to benefit from its advanced features. That’s a pretty disrespectful thing to ask of them.

1 Like

I understand.
Fully.

But let me add, that exporting from Drafts is not or not easily possible without a Pro subscription.

And as much as I understand the need to earn money for the developer of such a fantastic App, exporting really should be possible without a subscription!

And I say this as a former subscriber.

The default app, as it ships in a new installation, has complete support, on both iOS and Mac, for exporting via numerous methods, including, but not limited to:

  • Export feature which supports export as text, CSV and JSON of multiple drafts.
  • Backup feature which provides full-data exports of all data in JSON format.
  • “Export” action in the Basic group which allows you to export on-demand any draft to a file destination of your choice.
  • “Save to…” example actions that can export to iCloud Drive, Dropbox, Google Drive, One Drive, Box and other file storage systems.

I don’t think you’ll find any other app with more out-of-the-box, free-to-use export options - nor one that provides more-or-less infinite options to customize the method, format, and content of those export. In almost any other app you are stuck with whatever limited options they provide.

2 Likes

True.
And yes, those are fantastic possibilities!

But you cannot get out a selection (or all) drafts as multiple text files and this is what we talked about.

I could do now, with the action from @sylumer but would loose the first line in every file.

I have no idea how to get the files out of a JSON backup - the trick with Bear did not work and I don’t have some “json editor” …

So, I will try with a CSV export and some awk code! This may work.

But a “regular” user could not do this - he would get stuck and never be able to export a large number of drafts as files.

And this is what I meant - there should be such an (easy) way to get your stuff out, for a simple user who just wants to edit some files.

And I feel, it would be fair that this works without a subscription - even as I understand that you see this in a different light.

Thanks for your post!