Keyboard Maestro macro/Applescript: new markdown file from selection

One of the features I loved about VoodooPad was the ability to create new Markdown files by selecting a word and pressing ⌘L. This macro allows me to do that and it will also open a prompt asking for text to be placed in the new file. The exact content of the file can be adjusted, of course, and I left two templates of sorts to help with that. It is set to create the file on the same group whence the word/command came from.

Hopefully it will be useful to others.
Feedback is always welcome.

Github repository with the file:
01)New text from selection.kmmacros

1 Like

Thanks for the macro! For those who don’t use Keyboard Maestro here’s a script that should do the same:

tell application id "DNtp"
		if not (exists think window 1) then error "No window opened."
			set invalidName to false
			set theName to selected text of think window 1
			if theName is "" then set invalidName to true
		on error
			set invalidName to true
		end try
		if invalidName then error "No text selected."
		set theContent to display name editor info "Please enter the Markdown note:"
		set theMD to "# " & theName & return & return & "{{TOC}}" & return & return & theContent & return
		create record with {name:theName, type:markdown, content:theMD} in the current group
	on error error_message number error_number
		if the error_number is not -128 then display alert "DEVONthink" message error_message as warning
	end try
end tell

Just save it in ~/Library/Application Scripts/com.devon-technologies.think3/Menu as “New Markdown Note___Cmd-L.scpt”.


That is awesome, Chris @cgrunenberg. Thank you for the script :slight_smile:

Can you post an example of how you’re using this?
I am confused by the {{TOC}} since that’s internal linking, not to an external document.

Actually, {{TOC}} is just part of the text of the newly created markdown file.

I understand the TOC can be used in the Markdown document - assuming you are doing further editing and adding sections to it.
But what’s the point of the document itself?

I don’t understand what a file with an H1 header of the copied text, a TOC under that, and some other text would be used for.

I have a lot of text in MD in my wiki. So If I am reading or writing on DT3 and find something interesting about a concept that is worth a separate page just for it and there is a section of the text that I want to add to this new page:

  • I copy the text I want to add to the new page.
  • Select the concept and activate the script.
  • I paste the text and voilà: I have a new MD page with the concept as the record’s name and title (h1). Below it there will be my wiki’s menu (which goes to every page) and finally below is the text I copied.

Digging this up a little to ask: what are you using to generate the actual menu from the {{TOC}}? I know iA Writer interprets ToC but only by looking at the headings in the current file, and only when rendered. Does your workflow include a real Table of Contents pre-preview?

Not sure if I understand the question.

If you add {{TOC}} to the text, Multimarkdown will render it as a table of contents in preview mode. {{TOC}} is there as just a piece of text.

Regardless of this, DT3 will add all headers to the toc in the sidebar.

Thanks for the quick response.

I understand—I misinterpreted your posts above. I thought…

…meant that you were embedding a ToC in each document that linked to the rest of your wiki, and I was interested in this marvel of a menu placeholder.

Alas. I understand MMD {{TOC}} placeholders. Just thought this was something special.

Oh, I see. I just add the same text to the top of all md files linking to the main pages in my wiki.

Corp. | Arc. | Plat. | Arist. | Hist. | Gloss. | Zk.

Since I use auto-linking, this is enough to take me where I want to go.

1 Like

Huh. That is super clever. Obvious in retrospect. Thanks for the tip!

1 Like

Corp. | Arc. | Plat. | Arist. | Hist. | Gloss. | Zk.

So these are live links due to Automatic WikiLinking with Names & Aliases (likely aliases in your case) ?

Yep, that is correct.

Nice :+1: :slight_smile:

If I would want to implement similar behaviour but only in one DB out of multiple i have - is it possible?
My reading of the settings is that I can only globally choose between md-style wikilinks vs names+aliases. I was experimenting with ideas from @Bernardo_V for a wiki but I still want to preserve my existing [[]] links (as they also work with 3rd party md IOS tools). Can we make this alias feature work on a DB level somehow in addition to [[]] linking?

This is not possible, unfortunately :disappointed:

1 Like

No, this is not supported. There is one WikiLink preference to choose.

I would consider this a nice feature to look into

This would allow to have one DB which would leverage @Bernardo_V alias linking approach for organising reading material and a second DB which would use wiki-links for things like notes, references, zettelkasten etc.

The request is noted but you have to consider the technical requirements to implement such a thing.

1 Like