Create a Markdown Doc and open it in another application

No worries.

Personally, I’m not sure why you’re using Keyboard Maestro, other than familiarity?

DEVONthink has templates you can create and use so you could merely use one and press Shift-Command-O to open it in the system default application (if set to Typora).

Also a template can be imported via AppleScript.

So there are two parts of the equation…
Here is an example template (housed in ~/Library/Application Support/DEVONthink 3/Templates.noindex/My Templates)…

%title%_%hour%%minute%%second%.md.zip (872 Bytes)

Note the name has default placeholders, e.g., %hour%, that will be resolved when imported.

And here is a simple AppleScript that not only imports the templates, it makes use of a custom placeholder for the title (which also applies to the filename), but simply opens it in Typora after creation.

set boilerplateTemplate to "~/Library/Application Support/DEVONthink 3/Templates.noindex/My Templates/%title%_%hour%%minute%%second%.md"

tell application id "DNtp"
	set docTitle to (text returned of (display dialog "Enter the title:" default answer "My Note"))
	
	set newRecord to import boilerplateTemplate placeholders {|%title%|:docTitle} to current group
	set newRecordPath to (path of newRecord)
end tell

tell application "Typora"
	activate
	open newRecordPath
end tell

DT Custom Markdown to Typora.scpt.zip (2.5 KB)

Here’s an example result, including Typora having launched and opened the file…

1 Like

I’m not sure that I got all the subleties here, but in my words:

  • you want to create a new MD file from KM
  • this MD file should be created inside DT
  • after creation, you want to automagically open it with the program associated with MD files

Assuming this is correct - why not create the MD file in DT with a template and then open it from DT? Or use a script in DT (it is actually scriptable :wink: that creates an MD file? As @blanc suggested, it could create that file in a specific group and a smart rule could watch file creation in it, opening the new arrival with the default external program.
Something like

(()=> {
const app=Application("DEVONthink 3");
app.includeStandardAdditions = true; /* needed for GUI methods */ 
const response = app.displayDialog("Titel für Notiz?", { /* ask for Title */
    defaultAnswer: "",
    withIcon: "note",
    buttons: ["Abbruch", "OK"],
    defaultButton: "OK"
});
if (result.buttonReturned === "Abbruch") return; /* Cancel clicked, abort */
const titel = result.textReturned; 
/* determine zettelUID here */
const template=`Typ:
Titel: ${titel}
Datum: ${Date()}
Note/Resource ID: [[zettelUID]]
....
`;
const rec=app.createRecordWith({name: "Name could come from a dialog", type: "markdown", plainText: template});
})()

This would create the record in the global inbox. I’m not meaning to say that KM is not up to the task. I’m just suggesting to reduce complexity by using only one program here. Although it remains to be seen if this amount of scripting reduces complexity :wink:

@BLUEFROG @chrillek

You are simply genius!

Thanks so much - i can finally settle with these solutions :slightly_smiling_face: :upside_down_face:

I’am using DevonThink Pro since last week. It is amazing how deep you can go.
And it is very very nice how helpful the DT - community is.

Consider me a truly fan now and have all my thanks for your kind assistance.
At the end the whole process is really fun and especially with scripting i can learn a lot.
It is nice that KM is not really needed at last.

at Blanc:

Thanks so much for your help, too.
With your help i understand intelligent rules a bit better and i can see how powerful you can use this tool.
And yes, you are right - working my way up the DT-foodchain… :grin:

1 Like

You’re welcome :slight_smile:

I was looking for a quick way to open markdown file by the OS default markdown editor.
And just noticed that there is a shortcut [cmd + shift + O] for my need in DT3. Shown as below
Screen Shot 2021-08-12 at 12.29.10 PM

Just a quick update in 2021.

Welcome @xygod

Indeed! That is a long-standing shortcut to open documents externally. Glad you found it :slight_smile: