I’ve not had time to test my code, but it should hopefully point you in the right direction.
Alternatively, press and hold on the select button on iOS, and then execute one action on all of the selected drafts (every draft in your current workspace view will be selected). In hindsight that’s probably easier than the code I thought up
Sorry to revive this topic but I tried to do the same thing (export multiple drafts) in Dropbox.
I cannot see why it doesn’t work. I’m new to scripting and I would really appreciate some help if it’s possible.
Here is my code:
let db = Dropbox.create();
let path = “/myPath/”;
let draftsGroup = Draft.query("", “all”, [“myTag”]);
db.write(path, myDraft.processTemplate("[[safe_title]].txt"), myDraft.content, “add”, false);
Thé code runs but it does nothing in my dropbox !
To try to understand, I read this thread and ran this code which worked fine.
Thanks – I was able to do a sloppier version of this, so this will be helpful for cleaning up. But I was hoping to preserve the actual metadata. I emailed support and it seems not possible within Drafts and will require learning whole new skillsets (AppleScript or some other scripting), which I guess is nice from a personal growth perspective but not from a UX perspective.
I was impressed recently by both SimpleNotes (which preserved all metadata since 2011 and exported to text file in one button on my phone) and Ulysses (which lets you drag notes out into finder and also preserves metadata). These are both similarish apps, so I was sad to see the feature missing from Drafts.
Drafts has metadata that isn’t present for text files such as creation location, so a blanket export from the Drafts database to a file isn’t necessarily a round peg in a round hole sort of action.
What Drafts is really good at is being extensible to ways of working and personal requirements. It also has a strong community of helpful people, including the developer. That combination puts it head and shoulders above many other apps in terms of capabilities.
I’m sure that if you started a thread on what you want to do exactly in terms of your export, and how far you can get/have got on your own, others would be happy to help. In fact there’s a good chance that many others could find it useful too.
I’ve used and loved Drafts for years, but it’s always been in a weird tension with my ever growing folder of plaintext notes. I was considering going all in on Drafts until I saw that I couldn’t easily leave. Portability > extensibility for me, personally. Still one of the best apps going though.
Funny solution: I imported everything into Bear and then immediately exported everything from Bear. Problem solved in ~6 min (not including a couple hours of googling).
Intermediate drafts user here - I’m considering exporting my drafts as a JSON file (which seems to preserve much of the metadata) and parsing that file with some sort of script. Has anyone tried this option (or is it not possible because of something I’m missing)?
I want my drafts to end up as individual .md files (preferably with metadata) that I can archive somewhere like Devonthink.
The File action step can be configured to write as “.md” files, maintain creation/modification dates, and assign drafts tags as Finder tags.
I would suggest you just configure an action using the File step to write the files the way you want them to the destination you want them (within iCloud Drive). You can then bulk export using “Run Action” on selected drafts in the draft list, or create another batch processing action that queues the action to run on all drafts in a workspace, or that match a query if you need a more automated export option.
I found out, to my dismay, that my “Save as .md” export action item, which is customized from Save to file as… , does not modify the file meta data, so I lost the creation dates when I export my drafts into iCloud Drive. I exported about 10 notes from Drafts today and all the “Date Created” were set to today
I searched the forum and File action has a parameter to “maintain” Create Date. I need Export so that I can choose the folder to save the file. If I use File, I don’t think it will pop up a dialog box to choose the location.
Update: I can use File with Bookmark to save to specific location but I’d REALLY like to be able to choose my folder.
Appreciate any guidance.
TL;DR - is there a way to use Export function and preserve Create Date?
The Export step cannot set the creation date or other metadata. It is a system function, like a Save as dialog on Mac, Drafts is handing off the content to the system, and the file selection/write process is all handled out of the app’s process because of sandbox security.
If you want to update that information, you have to use the File step or a scripted action, and it has to write to the “Drafts” folder in iCloud Drive, or a bookmarked folder, so that Drafts has security permissions to access that file.
You could, in theory, write a scripted action that provided a custom file-picker, but it would be limited in scope to only one of those destinations.
Thanks for confirming. I’m thinking of a hack using Hazel to monitor my Obsidian data folder and grabbing the [[created]] date from the first line of an exported Drafts to set the file meta data. A bit of a stretch, but I guess that might work out. Thanks again.
I found myself with similar needs to the folks in this thread, and wrote a script today that bulk exports all the drafts currently visible in your drafts list. It preserves the created/modified timestamps on export to the file system, and will use the first line of each draft as the filename.
It has a couple cautionary checks to make sure you have reasonable filenames and to give you a preview of the results before executing.