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..
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
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 forrecord newNote. works.
Is there a list of Applescript commands the DT understands ?
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).
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: "◀︎ ";
}
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?
@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)
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…
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…