Creating related notes by right clicking?

You’re welcome! I asked how much you understood because posting the adjusted script in full seemed at bit much, but I wasn’t sure if posting a snippet was enough. Great that you could make it work. :slight_smile:

The category list + dialog I shared earlier stores your choice as a text string in the variable theCategory. You can use that wherever you want. In the example I use it to immediately create the variable noteCategory holding the text string [Category] (space included) for use in the item name. I just felt that was cleaner to read.

If you want it in the H1 of the note, this will do:

-- Create linked note
set theMarkdown to "# [" & theName & noteCategory & "](" & theLink & ")" & return & return

If you want it in the H1 – but not as part of the link – do this:

-- Create linked note
set theMarkdown to "# [" & theName & "](" & theLink & ")" & " \\[" & theCategory & "\\]" & return & return

(Notice that I’m escaping the brackets. If you end a header with [Some text] in multimarkdown, the bracketed text does not render because it is interpreted as a custom id attribute for the header.)

Or if you want it as a H2 under the image, you could go for this (this time without brackets):

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

Or as a tag:

set newNote to create record with {..., tags:theCategory}

BLUEFROGs script distinguishes between images and other records, and the “Transclusion” comment specifically concerns the records that are not images :wink: (Transclusion is in this context a feature of multimarkdown that lets you render one document as part of another using the ‌‌{{ }} syntax. Image links already do that for images, transclusion is mainly useful for other text files.)

Regarding custom metadata, I simply wasn’t sure if I had understood you and wanted to point out that it has many uses besided See Also & Classify. It all depends on what you’re trying to do, of course.

2 Likes

thx, @troejgaard

all very kind in the way you provide assistance!

I could make this work after adding an “end if”

set theMarkdown to (theMarkdown & imgLink & "## " & theCategory & return & return)
end if
set newNote to create record with…

so, if others want to replicate, I guess they could use this:

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

I am now a step further in making DT a more natural habitat for working with images alongside text!
– so, thanks a load for your help.
Some things are easy for some. And the other way round… :slightly_smiling_face:

Nice to have such helpful people like you around in the DT-forums! :sunflower:

2 Likes

I didn’t notice that I missed that line in my copy & paste. Good catch.
If-statements always need an end if unless they are kept to a single line.

I guess you’d still want the H2 category when you create a linked note to something that’s not an image:

-- Create linked note
set theMarkdown to "# [" & theName & "](" & theLink & ")" & return & return
if type of theRecord = picture then -- Add image link:
	set imgLink to "![](" & theLink & ")" & return & return
	set theMarkdown to (theMarkdown & imgLink & "## " & theCategory & return & return)
else
	set theMarkdown to (theMarkdown & "## " & theCategory & return & return)
end if
set newNote to create record with ...
1 Like