How to preserve create time and modification time while importing?

How to preserve create time and modification time while importing?

I have lots of “md” files created by iA Writer, and I would like to importing all of them to Drafts. But the only problem is all these drafts would be “created” now, which ruined my review process and workflow on my drafts. I would like the “created” and “modified” timestamp to be the same as the file’s info.

I tried use “automatic import” feature, and the “scripting” too. The “FileManager” class does not have any method to retain file info.

So is it possible to achieve that? Thanks

Update:

Cannot change draft’s created time and modified time through scripting too

The only way to import creation/modification date information currently is via Drafts native JSON export format. Which looks like:

[
  {
    "created_at" : "2020-02-24T13:45:57Z",
    "tags" : [

    ],
    "accessed_at" : "2020-02-24T13:45:57Z",
    "uuid" : "39EA5821-A1A5-4DE6-AD06-F17381A24D85",
    "folder" : 0,
    "languageGrammar" : "Markdown",
    "created_latitude" : 0.00000,
    "modified_longitude" : 0.00000,
    "content" : "Test Draft",
    "flagged" : false,
    "modified_latitude" : 0.00000,
    "created_longitude" : 0.00000,
    "modified_at" : "2020-02-24T13:46:04Z"
  }
]

If you created this format outside of drafts, named the file with a .draftsExport extension, and import it you would retain the date information.

It not necessarily a bad idea to allow script access to some date values, but no one has ever requested it, and it presents some complexity to avoid the automatic mechanisms for maintaining and updating those values from conflicting with manually set values.

3 Likes

Thanks so much for this workaround.

And thanks for creating this awesome app too. It actually simplified my whole workflow so well. That’s why I’d like to import all of my texts to it to keep unification.

I am trying to import text files using this method, going from Day One JSON to Drafts. How can I create the UUID for the drafts JSON? I’ve got all the other keys mapped from the Day One JSON output to the Drafts JSON import, but Day One uses a different UUID format.

Thanks!

1 Like

Drafts will generate a new UUID when importing, so I think you can just leave that blank or omit the key.

1 Like

I can confirm that this works. Thanks!

1 Like

I am trying to import all of my bear notes into Drafts, while preserving create date and time. I have exported them as .md, renamed them .draftsExport. Bear doesn’t have a JSON export option. When trying to import to Draft, but I get an “Import Error - Unable to load import file. Import cancelled. Error: The data couldn’t be read because it isn’t in the correct format.”

Is there another format I can use from Bear that will allow JSON export? Thanks!

Maybe this thread could help:

The code (python) is on github.

1 Like

I’ve already download both yours and @gcaprio 's scripts. I have read a few tutorials, but haven’t been able to figure out how to get the python script to run. I have tried modifying it where the command line is showing errors. It appears that being an orthodontist does not equip me with the skillset to competently run python scripts. Thanks for all your work on this!

ok. if you like I can coach you through the python 3 setup.

That would be amazing! Just let me know how to make that happen.

@jessegray, just in case you haven’t got the Python approach working yet, and for anyone else looking to do this in the future I’ve been working on some updates to the ThoughtAsylum Action Group Suite, and along with a whole new class for TADpoLe for working with the Bear URL-scheme “API”, I’ve added a set of actions for working with Bear.

The ThoughtAsylum - Export/Import/Share action group contains a couple of actions that work directly with Bear to import notes into Drafts (there’s also an export too for those wanting to send a draft to Bear with Drafts tags intact). You can find the Bear-related actions in the Bear section of that action group.

TAD-Import Note From Bear

Enter the ID of the Bear note to import and specify any additional tags that should be applied to it. All Bear tags will be copied across as drafts tags. The creation date will also be copied across.

TAD-Import Notes From Bear

Enter a set of search criteria to run against Bear. All matching (non-trashed) notes will be (bulk) imported into Drafts. All Bear tags on a note will be copied across along with the content of the note. The creation date will also be copied across.

@jessegray, if you are still looking, this second one is probably the one you would be most interested in as you are looking to import all notes. Run the action, leave the search term and tag blank. Consider adding some tags of your own (e.g. “import, bear”), and then let Drafts request the details of each note and build a draft for it.

2020-12-31-21.44.24

If you want to just run a quick test, try setting a specific tag or specific search term to bring across a small sub-set of notes. I don’t use Bear much, so my scale of notes isn’t that far into double figures. Should volume be an issue for anyone, then I would suggest batching up notes by using the search and tag constraint criteria to bring the notes over in groups.

Hope people find the Bear stuff useful.

FWIW, the ThoughtAsylum - Export/Import/Share action group also has an action in it for importing files, maintaining creation time (based on file creation), and importing front matter specified tags.

TAD-File Import With Tags

Import files into Drafts, transferring file creation and modification timestamps, as well as specifying and importing simple front matter tags.

1 Like

Just another note of gratitude. Had cause to import 3000+ notes from plain text files this evening, various sources. Gathered everything in Bear then ran the TAD importer. Worked like a dream.

2 Likes