Creating related notes by right clicking?

Hi, I am storing (importing) pdfs and png files in DT4. I would like to add notes in different contexts (think “colours”) to those files and be able to search in notes in a specific colour only . Finder comments and Annotations don´t seem to work as I can only add one per file.

So I thought I can use templates (right-click: new from template), but the templates I tried will create a standalone note with no direct relation the file on which I did the right-click. Of course I could copy the link of the pdf and paste it in the note, but thats too cumbersome. Isn´t there a way to create a dependent note from a file ? There also doesn´t seem to be placeholder to accomplish that..

Thanks for any insights here…

Alex

1 Like

oh..looks like new from template → note. does exactly that. )

Like in many cases AppleScript is your friend. Here’s a simple example:

tell application id "DNtp"
	set theGroup to current group
	repeat with theRecord in selected records
		set theName to name of theRecord
		set theLink to reference URL of theRecord
		set theMarkdown to "# [" & theName & "](" & theLink & ")" & return & return
		create record with {name:theName & " [Note]", type:markdown, content:theMarkdown} in theGroup
	end repeat
end tell
2 Likes

I wasn´t right above: the template just pastes a copied url…

Thanks for the applescript. I´ll try it.

That works. Is there a possibility in Applescript to have newly created note in focus ? without having to look through the list of files ? reveal newNote and open record give me error messages in DT4. Only open window for record newNote. works.
Is there a list of Applescript commands the DT understands ?

DEVONthink“ hat einen Fehler erhalten: record (content id 33930 of database id 2) versteht die Nachricht „select“ nicht.

Just drag & drop DEVONthink onto the Script Editor.app in the Finder or Dock.

Welcome @newuser2025 :slight_smile:

DEVONthink has a great manual, I suggest using it. See Automation > Basic AppleScript Terminology > DEVONthink’s dictionary. (Which is followed by DEVONthink Windows)

Without context we can’t tell what’s going on. Please show the whole script. Where does select come from?

Here’s a quick modification of @cgrunenberg’s script. Works in DT3, I think it should also work in DT4.

-- Create & open linked markdown note

tell application id "DNtp"
	set theGroup to current group
	set theRecord to (selected record 1)
	set theName to name of theRecord
	set theLink to reference URL of theRecord
	set theMarkdown to "# [" & theName & "](" & theLink & ")" & return & return
	set newNote to create record with {name:theName & " [Note]", type:markdown, content:theMarkdown} in theGroup
	
	-- 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
	
	-- Note: Include only one option
end tell

Since you want to open the note immediately, this version only works on a single item (or if you by chance have multiple items selected, the first one).

3 Likes

I had used a “select” command but that´s apparently not a AS command that DT understands.

The edited code works and I think I can also work with that :). Thanks !

You’re welcome. I actually hadn’t considered something like this, so it’s also a nice addition to my own scripts.

I’ll add a little bonus inspiration:

For annotation-style notes, I personally don’t want a big H1 with the parent document name. I just want an unobtrusive item link at the top. So I added this to my stylesheet:

/* Back-link at start of annotation files */
body > p:first-of-type:has(a[href^="x-devonthink-item"]) {
	font-size: .9em;
	margin-block-end: 2.5rem;
	font-family: var(--font-sans);
	color: var(--color-tx-muted);
}
body > p:first-of-type:has(a[href^="x-devonthink-item"]) > a {
	color: inherit;
}
/* ... with a back-arrow */
body > p:first-of-type > a[href^="x-devonthink-item"]::before {
	content: "◀︎ ";
}

Which gives me:

(In case you’re not familiar with CSS, var(--font-sans) and var(--color-tx-muted) are defined elsewhere, you would need to change those)

3 Likes

That is very helpful

This is a slight tweak which perhaps others may find helpful as well - it creates a new subgroup containing both the original file and the new depeendent note:

tell application id "DNtp"
	set theParentGroup to current group
	
	repeat with theRecord in selected records
		set theName to name of theRecord
		set theLink to reference URL of theRecord
		
		-- Create a new subgroup named after the original file with " - with Note" appended
		set newGroupName to theName & " - with Note"
		set newGroup to create record with {name:newGroupName, type:group} in theParentGroup
		
		-- Move the original record to the new subgroup
		move record theRecord to newGroup
		
		-- Create the dependent note in the new subgroup
		set theMarkdown to "# [" & theName & "](" & theLink & ")" & return & return
		create record with {name:theName & " [Note]", type:markdown, content:theMarkdown} in newGroup
	end repeat
end tell

Question - how do you post a script with the “Open in Editor” box?

1 Like

Start the code block with ```applescript.

1 Like

@rkaplan Sidenote: the syntax highlighting assumes AppleScript by default even if it doesn’t show the button. So if you post code besides AppleScript it gets confusing to read unless you specify the language explicitly. (For no highlighting just put ```txt)

1 Like

I have a related question: so I now have notes that include a backlink to my parent file (pdf). How can I see all notes attached to that parent ? In inspector 3rd menu there is “Erwähnungen” (Mentions ?). Is this the only way ?

I also noticed that although I see multiple mentions in inspector for the parent, they are not all displayed in the graph section of inspector..so f.e. 2 mentions - just one relation in graphs…

They aren’t attached; they are linked so have you looked at the Document > Links inspector?

yes, they are there, too. And in mentions. But the inspector graph only displays one, whereas in these 2 places i see the correct 2 notes each.

Be aware that mentions aren’t links. They are just occurrences of a document’s name or aliases in the text of a document. You are only seeing them due to the specific document you’re creating.

And screen captures of the inspectors would be helpful, i.e., “I also noticed that although I see multiple mentions in inspector for the parent, they are not all displayed in the graph section of inspector..so f.e. 2 mentions - just one relation in graphs…”

This is what I’m seeing in the Mentions and Graphs inspectors using the document from the earlier script…

but in graph just one mention..looks like only the newest is displayed