Tags to hashtags in a way similar to Bear app

Bear is the only other app I eventually use for taking notes instead of DEVONthink. It has a beautiful interface, but even more importantly, it organizes notes by hashtags inserted to the body of the text. You can either type the hashtag directly or drag the note to the tag upon which it will insert the tag to the text in a manner consistent with the tag hierarchy parent tag/child tag/and so on.

In DT3 it is already possible to create tags by typing them out in the text. It is not possible, however, to have the tag inserted to the body of the text by dragging it to the tag folder, or by adding it in the inspector. This, I think, is desirable to keep the tags synced in both places.

I started to work on this with a Keyboard Maestro macro.
Here is what I have so far: a macro that inserts the tags that are missing to the text.
Here is what I am still figuring out how to do:

  1. Get Record tags in a format that is consistent with the tag hierarchy (parent tag/child tag/and so on).
  2. Trigger the macro/script automatically. (Is there a way to call a script every time a record is updated?)

Here is the macro:

And here is the file

I found a way to do it using this script I found here in the forum

tell application id "DNtp"
	set theParent to get record at "/Tags"
	set allTags to my getAllChildTags(theParent, "")
end tell

on getAllChildTags(theParent, theTabs)
	local l, theTagList, tagName
	set theTagList to {}
	tell application id "DNtp"
		set l to children of theParent whose tag type is ordinary tag
		repeat with theChild in l
			set theTagList to theTagList & ((theTabs & name of theChild) as string)
			set theTagList to theTagList & my getAllChildTags(theChild, theTabs & "/")
		end repeat
	end tell
	return theTagList
end getAllChildTags

Now I have to do some kind of cross checking to see which database tags match the tags in the file and then apply them to the text, ignoring the ones that are not.

I’m sure this is a wonderful macro, but isn’t it just simpler to do what you said initially: configure DEVONthink in preferences to convert hashtags to tags, and type the tag into the text.

Dragging documents to tags is messy, time consuming, and might end up in error if the document inadvertently gets dragged to the tag instead of replicant being created in the tag group the normal way.

I’m sure this is a wonderful macro.

Hi korm,
I agree with you. Perhaps I should have made my case a bit clearer: I already have a fair number of tags assigned to markdown files that are not typed out in the text. But still, I will think about what you said. There might be easier alternatives. (One of them could be using the above script to provide a list of tags and could be typed to the text). Thanks for chiming in :slightly_smiling_face:

Working in this, I noticed that hash tags don’t get picked up if they are in the bottom of a very long document. Also they appear in the table of contents (which feels weird). Christian @cgrunenberg, is this expected behaviour? (Sorry for the volume of questions in these past few days. I am working intensely and DT3 has been my companion in this).

Also they appear in the table of contents (which feels weird)

I am not seing this here. Are you sure you haven’t put a space after the # ? That would cause it to be read as a header and included in the table of contents.

Yep, just double-checked.

Oh… I thought you meant the Markdown table of contents. :slight_smile:

@cgrunenberg will have to look at that.

The rendering is currently (almost) completely handled by MultiMarkdown, the hashtags are only used inside the database & index.

But the hashtag is being detected as a table of contents item.

1 Like

I see. The next release will fix this.

1 Like

Hey @Bernardo_V,
How did you go with this?

I started typing my tags instead of adding them directly in the app.