Keyboard Maestro macro/Applescript: new markdown file from selection

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"
	try
		if not (exists think window 1) then error "No window opened."
		
		try
			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”.

3 Likes