Creating related notes by right clicking?

When I’m using DT for note taking, I’ll sometimes create a related note by entering a wikilink and then right-click, open in DT. That will create and open the new link in a separate edit window. I usually follow that up with the menu command to convert wikilinks to item links.

Or, if you want just one related note, would the feature to create an annotation file fill the bill?

wikilinks don´t work from png - only from text to text files. And I don´t think I can add more than one annotation to a picture.

As is to be expected. Wikilinks are used to connect text files. At least that’s what they were designed for. A link in an image sounds counterintuitive. Why not simply link to the image from wherever you want?

1 Like

because I want to attach searchable notes to images, not the other way round. my database is mostly png images and non-text pdfs..anyway using the applescript option above I found a workable way (the script creates a linked note automatically).

Have you considered converting your image files to PDF’s and annotating them?

1 Like

If you link to an image from multiple notes, won’t they be listed in the inspector’s list of links? Does that help?

Or, link to and from an image’s annotation file. As long as you create the annotation document with a link to the parent, you have a reference to your image.

yes, but I need to be able to search specific “types” of notes only..can´t do this with annotations as far as I´m aware..

How do you discern different “types” of notes, and what are the “types” you use. I’m uncertain what you mean here.

At the top, OP said

But that is also pretty vague to me. @newuser2025 If you describe your use case in more detail, it would be easier to offer suggestions.

Your follow-up was:

Didn’t the Document > Links inspector work fine?

If not, you could simply store all notes related to an item in the same group like @rkaplan mentioned earlier.

Or you could use the annotation file as a list of links to the other notes. That’s what @Amontillado is getting at. (You could modify the earlier script to also link created notes in the annotation).

Or maybe all these notes would make more sense as custom metadata?

1 Like

Since I already wrote it out, I’ll share. Here is one approach to linking the created note in the annotation file.

-- Prepare annotation file
if exists annotation of theRecord then
	set theAnnotation to annotation of theRecord
else -- Create annotation file if it doesn't exist yet
	set annotationGroup to (annotations group of database of theRecord)
	set annotationTemplate to "**Document:** [" & theName & "](" & theLink & ")" & return & return & "**Notes:**" & return
	set theAnnotation to create record with {name:theName & " (Annotation)", type:markdown, content:annotationTemplate} in annotationGroup
	set (annotation of theRecord) to theAnnotation
end if

-- Add link to created note in annotation file
if (type of theAnnotation is markdown) then
	set annotationSrc to plain text of theAnnotation
	set newNoteLink to "- [" & (name of newNote) & "](" & (reference URL of newNote) & ")" & return
	set updateSrc to annotationSrc & newNoteLink
	set (plain text of theAnnotation) to updateSrc
end if

The links inspector seems easier, but this might be useful if you have other links and want to see only the notes.

2 Likes

Think of a museum collection.my use case is analysis of charts, plans, pictures (non-text materials) according to different theories and contexts. I might comment a painting´s execution with “good”, and the general state of repair with good also. Then I´ll describe the picture content in a separate note that might contain “good”. But I need to be able to search for “good” only in “state of repair” context only. Futhermore the different note contents are unstructured and might be worked on by different people..(hence tags, etc. won´t work). It´s really like sticking differently coloured post-it notes to pictures :wink:

I am not very experienced with scripting, yet find your approach intriguing and would love to incorporate it into my workflow. However, Script Editor throws an error at me:

Do you have an idea what that means?

I believe @troejgaard posted a snippet of the relevant script but not the complete script.

right, that makes sense, as there is no “tell” “end tell” etc. thanks for pointing me to my error :slight_smile:

@rkaplan is correct. It is a snippet that could slot into the script I posted earlier in the thread (#8)

Since there are 23 posts in between, it might be better to show them combined. I also added an alert in case no or multiple records are selected:

-- Create & Open linked markdown note
-- Add link to created note in annotation file of parent record

tell application id "DNtp"

	-- Exit with alert if selection is not a single record
	if selected records = {} then
		display alert "No record selected"
		return
	else if (count of selected records) > 1 then
		display alert "Multiple records selected"
		return
	end if
	
	-- Main record variables
	set theGroup to current group
	set theRecord to (selected record 1)
	set theName to name of theRecord
	set theLink to reference URL of theRecord

	-- Create linked note
	set theMarkdown to "# [" & theName & "](" & theLink & ")" & return & return
	set newNote to create record with {name:theName & " [Note]", type:markdown, content:theMarkdown} in theGroup
		
	-- Prepare annotation file
	if exists annotation of theRecord then
		set theAnnotation to annotation of theRecord
	else -- Create annotation file if it doesn't exist yet
		set annotationGroup to (annotations group of database of theRecord)
		set annotationTemplate to "**Document:** [" & theName & "](" & theLink & ")" & return & return & "**Notes:**" & return
		set theAnnotation to create record with {name:theName & " (Annotation)", type:markdown, content:annotationTemplate} in annotationGroup
		set (annotation of theRecord) to theAnnotation
	end if
	
	-- Link created note in annotation file
	if (type of theAnnotation is markdown) then
		set annotationSrc to plain text of theAnnotation
		set newNoteLink to return & "- [" & (name of newNote) & "](" & (reference URL of newNote) & ")"
		set updateSrc to annotationSrc & newNoteLink
		set (plain text of theAnnotation) to updateSrc
	end if
		
	
	-- Open tab for created note (enable only one option)

	--- Option 1: Open note as tab in new document window
	---- open tab for record newNote

	--- Option 2: Open note as tab in current window and focus that tab
	--- (Works for both main & document windows)
	set theTab to open tab for record newNote in think window 1
	set current tab of think window 1 to theTab

end tell

Note: this is only written to work with annotation files in markdown. I’m relativly new to AppleScript and working with rich text is still beyond me. Since I barely use rtf anyway I’m not that motivated to crack it.


If you’re creating multiple linked notes like this… Another idea is to add a list of predefined categories to choose from, with the option of still entering a custom category.

-- Main record variables
...

-- Note categories
set customString to "{Custom}"
set theCategory to choose from list ¬
	{"Note", "Condition", "Motif", "Themes", "Technique", customString} ¬
		with title "Note category" with prompt ¬
	"Select a category for linked note" OK button name ¬
	"Continue" cancel button name ¬
	"Cancel" without multiple selections allowed
if theCategory = false then return -- Exit if list is cancelled
if (item 1 of theCategory) = customString then
	set theCategory to display name editor ¬
		"Note category " info "Custom category:"
end if
set noteCategory to " [" & theCategory & "]"

-- Create linked note
set theMarkdown to ...
set newNote to create record with {name:theName & noteCategory, ... } in theGroup
2 Likes

wow. incredible. Thank you so much for your script and ideas! Gosh, I love this community :heart_hands:

1 Like

It feels great to receive a response like that :blush: So let me thank you too!


By the way, it occurs to me that depending on how you navigate DEVONthink, the above might not always work as intended. I used the first item of selected records because that works whether you hide or show the View/Edit pane, which seems desirable. But—if you open multiple tabs in a main window, your selection in the item list doesn’t necessarily match the document in the current tab (which you can always get with content record).

At first I thought accounting for both might get a bit convoluted, but it should be enough to replace:

set theRecord to (selected record 1)

with:

if content record ≠ missing value then
	set theRecord to content record
else
	set theRecord to (selected record 1)
end if

… to ensure the created note links to what you see in the View/Edit pane when it is open.

Plus a slight adjustment to the alert:

-- Exit with alert if no document is displayed or selection is not a single record
if content record = missing value then 
	if selected records = {}
		display alert "No record selected"
		return
	else if (count of selected records) > 1 then
		display alert "Multiple records selected"
		return
	end if
end if
1 Like

many thx to @troejgaard for providing this helpful script –
– actually this seems one of two scripts in DT that really change the whole depth-of-engagement with DT for me, as it opens up a way to really work with context as content.

I am very reluctant w/ custom metadata, as it often does not fit my workflow, as the information there is not used in the onboard-AI and related search of DT, which for me is one of the main reasons to work in DT.

so, not being a script person – and probably being ‘uninitiated’ for the forseeable future, as we all have limited resources –, I would dare to make a request here, to those adept in scripting. Also in the hope this is also of interest to others w/ similar workflows like mine.

It would be fantastic if this script could be extended to do 2 more things:

  1. mention the note-type (from the great pick-list) in the title (– so it´s more visible)
  2. allow for an image-centered scenario, where the annotated image is included as transcluded link (and thus thumb within the note).

I know 2) is possible as @BLUEFROG once kindly provided me with a script that could do such a thing, via

set {recName, recLink} to {name without extension, reference URL} of theRecord
         if (type of theRecord) is picture then
		set theLink to "![](" & recLink & ")" as string -- Image Link
	else
		set theLink to "{{" & recName & "}}" as string -- Transclusion
	end if

… but given my non-parlance of Apple-script I couldn´t make an inclusion of this work myself.

Any hints, hands, and snippets welcome and much appreciated, indeed! :folded_hands:

PS: the other script that really turned my use of DT 180° was by @pete31Script: Search results with context

1 Like

I don’t follow. Mention the note category where exactly?

I don’t see why you want transclusion, but I can’t tell if you’re aware of the narrow technical meaning it has in this context. I’ll assume you just mean an image link.

The script already formats links according to markdown syntax. For image links you just need to add an exclamation mark.

Did you read through the script? Do you have at least a vague sense of what is going on, or is it all just gibberish to you?

I would add this small if-statement:

-- Create linked note
set theMarkdown to ...
if type of theRecord = picture then
	set imgLink to "![](" & theLink & ")" & return & return
	set theMarkdown to (theMarkdown & imgLink)
end if
set newNote to create record with ...

Are you only referring to See Also & Classify? I don’t know if custom metadata is considered there; probably not. But you can use it everywhere else—searches, smart groups, smart rules, batch processing and scripts.

1 Like

hey @troejgaard ,

the image inclusion works like a charm, helps a lot in contexts of annotating images, and is highly appreciated as option!

thx for taking time and energy!

I don’t follow. Mention the note category where exactly?

yes, sorry, that was a little bit vague. I actually meant the h1-part of the MD, where the link back to the original note is given programmatically.
– but that was just what I had in mind as very specific solution to the more general want of having the note category visiible in some of the main and visible parts of the doc itself.

I don’t see why you want transclusion, but I can’t tell if you’re aware of the narrow technical meaning it has in this context. I’ll assume you just mean an image link.

your description of what I want is to the point and adequate.
I used ‘transclusion’ bec in the original script that @BLUEFROG kindly handed to me (when I was asking for a way to carry over the/some custom metadata info of an image into an auto-generated image ‘contact sheet’) the resp. part of the script was annotated w/ the comment “transclusion” along with that part (– see Automatic / programmatic creation of file from image and content of its (custom) data field(s)? - #6 by BLUEFROG)

The script already formats links according to markdown syntax. For image links you just need to add an exclamation mark.

Did you read through the script? Do you have at least a vague sense of what is going on, or is it all just gibberish to you?

yes, I was aware of that. In principal.
… the problem – for me, personally – starts, where things have to be turned into scripted language – which is unforgiving and not open to any ambivalency, down to small details of syntax, as you know.

So, I did read through the script, and as I said I tried to somehow get @Bluefrogs aforementioned part of the script inserting the image link (– yeah, let´s maybe not call it “transclusion” in this context) into yours.
But – without any proficiency in scripting – my reading relation to the script(s) was somewhere between “half knowledge”, “intuitive understanding”, “informed guesswork”, “tinkering” … and “gibberish” :smiling_face:
This fact is also the very reason why I was asking for some help here. :grinning_face:

… and, I am very grateful for you extending it here! This part works like a charm, and will help me a lot! Thanks!!

I can’t tell you just how much a visual cue / reference back to imges helps, when annotating them this way in DT :grinning_face_with_smiling_eyes:

Are you only referring to See Also & Classify? I don’t know if custom metadata is considered there; probably not. But you can use everywhere else—searches, smart groups, smart rules, batch processing and scripts.

It is not considered. The definition of “content” in DT is very strict, and vehemently separated from metadata of all kind. I can see historical and other reasons for this, as DT started as text-centric/-logic app, based on firm separation between textual content and “additional” “meta”-data.
I would say (and argued in some places) that this is not always helpful when dealing with non-propositional/-textual content, like images, where metadata (like description; IPTC title etc.) would very much deserve to be considered as part of the “content” – simply for the purpose of things like automatically finding / seeing semantic relations (“related content”) when images, audio, video, PDFs etc are mixed (pretty much ‘the modern document situation’)

Regardless of that, I thank you for your comment / remark here as well.
In this case, though, I was indeed referring to the “just” of “See Also & Classify” and automatically retrieved / surfaced related content.
In a lot of contexts (workflows) and for a lot of people here in the forum it is exactly this part of DT – “see also” (or “concordance” and automatic indexes) which are valued as ‘the heart’ (or “USP”) of DT.
I am aware, though, that these other aspects / functional spaces which you mention do work with metadata (I am very grateful metadata are part of search now!).

And, as you hint, there are contexts where indeed scripts, smart rules/groups are just as critical as “see also” or “concordance”. It just remains true that in a lot of contexts “related content” and “concordance” remain critical; and it would help if the (some) metadata would be (optionally) included – especially in scenarios where one (also) deals with non-textual documents. Just a particular take & side-issue here, motivated by working a lot and systematically with such ‘non-textual’ documents.

Now, if someone can carry me across the last red “gibberish”-line, helping me to automatically / programmatically insert note-type – that you so elegantly included into the script – into the note-body (somehow), I’d be even happier. If not, I will certainly find ways around, … tags… or something…From a practical standpoint, not as a big deal as image inclusion. :otter:

So, thanks again, @troejgaard !