Creating new DEVONthink documents from clipboard text

I have recently moved to a new mac. On my old mac I used to create plain text documents in drafts.app, then cut or paste the draft text to clipboard, and create a new document in DEVONthink with the clipboard text using command+n. The resulting draft would always be created as a .txt file, even if the original text of the draft included markdown formatting such as ## or [link](https:.. …).

When I follow the same workflow on my new mac command+n only creates .txt files if there is no markdown formatting present. If any markdown formatting is present then it creates .md files instead.

I’m not sure why the behaviour is different, but I prefer to only have .txt files when I move documents from drafts.app in this way. Can anyone suggest what I need to do on my new mac to recreate this behaviour?

Thanks

Do you use the same version of DEVONthink on both computers? Recent versions automatically detect whether the clipboard contains Markdown or not.

Excellent question. I thought I was. However it turns out I am using 3.9.10 on my old mac, and 4.0beta3 on my new mac. I knew there was a v4beta available but I didn’t intend to download it. When setting up my new mac I must have picked that one by mistake.

At least it turns out that 4.0 works very smoothly with VoiceOver. So smoothly, in fact, that I didn’t even notice the difference - but then I wasn’t looking. I will have a play about with the new features and see what I think.

With regard to my markdown issue, I would like to have the option of choosing .txt as a default. However if this is not going to be possible going forward I will have to give some thought as to how I can change my workflow to get the result I want.

Why? On macOS, a lot of software (if not all) rely on the extension of a file to mean something. So, MD editors will consider the extension .md to mean “markdown”, while they might ignore files ending in .txt.

Personally, I find the idea of attaching meaning to a file extension weird. But most people on macOS seem to prefer that, as does the OS itself.

Re Drafts: You could have and still can use an action to export from Drafts to DT. Which might be a tad smoother than copying to the clipboard and inserting from there.

@SausageSandwich - For what it’s worth, I’m getting the same behavior you describe.

In DT 4b3, if the clipboard content includes markdown formatting, the file created using Command+n has the extension .md.

In DT 3.9.11, the file created using Command+n has the extension .txt even if the clipboard content includes markdown formatting.

For my money, the way DT 4b3 handles this is a feature, not a bug. After all, it makes sense that if your document includes markdown formatting it would normally be a .md file. But I suppose it would be nice if the user could control that behavior.

1 Like

The drafts action is great, and I use it sometimes. I’ve also checked and it does keep the .txt extension in v4beta3.

The only problem with it is that it sends everything to the inbox. The reason I cut and paste is that it allows me to sort everything into the correct folders at the same time. Probably what I need is a slightly more advanced drafts action that opens DEVONthink and allows me to pick a specific destination each time. I don’t know if anyone has made one of those but I will check the drafts directory.

Incidentally, the reason I prefer .txt files sometimes is because, though the contents may visually look the same on screen, the VoiceOver screen reader treats the files quite differently. Navigating rendered markdown files is more like using web pages, and for my notes I just want plain old text that only gets rendered to markdown when I share it with someone sighted who needs the correct formatting.

1 Like

The action I see in my version of Drafts is simply this

x-devonthink://createMarkdown?title=[[title]]&location=''&text=[[body]]

and there’s nothing you could do to this command URL to have it open a group selector, I think.

After some investigation, I came up with this Drafts Action. It consists of a single “Run AppleScript” step which executes this code

-- AppleScript content
-- Editing and testing in Script Editor recommended
on execute(draft)
    set t to title of draft
    set c to content of draft
	tell application id "DNtp"
		set targetGroup to display group selector "Select group to save MD document to" with name
		set rec to create record with {type:markdown, name:t} in (selected group of targetGroup)
		set plain text of rec to c
	end tell
end execute

The code is minimally tested, in that I run it to copy a single MD document to a group.

I apologize for any bad AS code here, as I’m not an AppleScript person.
But it is impossible to do that in JavaScript because Drafts does not support JXA. Not the only weird thing about it, IMO.

In case someone is wondering about the two-step record creation (creation first, setting the plain text later): I tried to incorporate that into the create record with command, but got an error because of newlines in the text. I don’t know if that is a bug or a feature.

3 Likes
x-devonthink://createMarkdown?title=[[title]]&location=''&text=[[body]]&noselector=0
2 Likes

One approach would be to use a general Send to DEVONthink action that opens the Sorter, like the one @BLUEFROG has posted (the &noselector=0 is the important part).

And for groups you use regularly just create additional actions. They could look like this: x-devonthink://createMarkdown?title=Drafts[[created|%Y-%m-%d]]&text=%0D[[draft]]&tags=[[tags]]&destination=95FDFC77-DA14-408F-AA00-2D7F2F8DA28E&noselector=1

But you should know that this does not allow batch apply. Which I find really annoying. The whole idea for me is to take notes fast (with Drafts) and stay in whatever app I’m using at the moment. If DEVONthink becomes the frontmost app every time I take a quick note I could have taken it directly in DT in the first place.

My solution is to keep the notes in Drafts but tag them with their DEVONthink destination. Then, later on, I use the File action, which is very simple but allows batch apply, to save all notes in one go in DEVONthink’s Inbox Finder folder. And there a Smart Rules takes over and moves them to their respective destinations.

If you use the File action in Drafts you should scroll down to tick the option to maintain the create and modification dates. And you should know that you could simple add “.txt” or whatever extension you prefer to the name field. Like this: [created|%Y-%m-%d-%H-%M-%S]].md

I like this idea, but I’m not sure what “File” action in Drafts you are referring to. Could you clarify please?
Many thanks for your help.

Sure.It’s the File action in the Service department of the Action steps.

Create a new Action, click the + icon, the scroll to Services and click File:

Then it’s just the fine settings:

Name: The default is [[time]], which is the current time in the format YYYY-MM-DD-HH-MM-SS. Please keep in mind that the idea was to be able to batch apply this Action, so this might cause havoc because this Action might very well create more than one file per second which means they would have the same name.

I went for [[created|%Y-%m-%d-%H-%M-%S]].md instead. Of course, you can use names completely without time stamps. But then their naming must be unique too. And yes, you can use any extension that works with plain text, like .txt.

Tags: The tags you have added to your draft in Drafts become macOS Finder tags which DEVONthink uses. The only downside is that Drafts’ tags are not case-sensitive.

The big box holds all the content: [[draft]] is everything in your draft, [[title]] and [[body]] are parts of the draft, i. e. the first line and the rest. You could add whatever you like, e. g. metadata. And just in case if you are wondering: I prepend every draft with an empty paragraph to disable metadata in DEVONthink.

Destination: Choose Bookmark. It’s the not so obvious name for a Finder folder to save to. And when you don’t have any Bookmarks and therefore can’t yet select any, it gets even less intuitive: You have to type a name (like “DEVONthink Global Inbox”) and then … no, you don’t select the folder in an Open dialogue. This happens only when you run the Action for the first time.

Advanced: If the date and time you actually wrote the drafts matters to you and not just the date the .txt file was created by this Action, tick this box.

Platforms: This is a Mac-only action, so do not enable it for iOS. In the left column of the action window you can make this action appear from Drafts for iOS/iPadOS completely. And vice versa for mobile-only actions.

And, again in the left column, there is After Success. It is quite handy to tag the draft after it has been sent to whatever other app for internal use in Drafts: Tag them “DEVONthink” and create a Workspace that shows all drafts tagged “DEVONthink”.

And just in case: When you want to apply this Action on a number of drafts, select them, context-click on them, click Run Action and click your “Send to DEVONthink Global Inbox” action.

This may sound overly complicated, but once it is set up, it works. Admittedly, the Run Action procedure isn’t anything like all drafts in an indexed Finder folder that get automatically moved by DEVONthink into one of its database. But like I said, for me this is the only big con of Drafts, by far outweighed by its pros when taking notes. I have developed a routine of moving the notes at least once per day and that’s okay for me.

Thanks a million. Never would have found this without your help

Just a final note of thanks - I set this up per youinstructions and it’s working perfectly.