@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