I trying to create a linked Zettel/item from an existing item in a specific database (ZettelkastenDB) with a template script. I think I am close to the solution but I am missing something as I can’t create the new item in the right location.
The target location structure is ZettelkastenDB/Zettelkasten/YYYY/MM
The important stuff is at the bottom. Thanks for the help.
Here is the script:
property pTemplateName : “Document”
tell application id “DNtp”
activate
set sourceName to name of content record
set sourceURL to reference URL of content record
set titleDateString to do shell script “date +%y%m%d%H%M”
set theName to (display name editor default answer pTemplateName info “Please enter a name for this document:”)
set theName to titleDateString & " " & theName
– display dialog theName
set theTemplateFile to (path to me as string) & “Contents:Resources:%myDoc%.md”
– display dialog theTemplateFile
set thePlaceholders to {|%myDoc%|:theName}
set the clipboard to ("[[" & sourceName & “]](” & sourceURL & “)”)
– set theRecord to import theTemplateFile placeholders thePlaceholders to the current group
– new Zettel to be stored in ZettelkastenDB/Zettelkasten/YYYY/MM
– Format the month number
set theDate to current date
set numMonth to (month of theDate as integer) as string
if the (length of numMonth) < 2 then set numMonth to “0” & numMonth
– Format the year
set theYear to year of theDate as string
– set theRecord to import theTemplateFile placeholders thePlaceholders to “/” & theYear & “/” & numMonth
if (exists database “ZettelkastenDB”) then
set theDatabase to open “/Users/manfred/DEVONthink/ZettelkastenDB.dtBase2”
set theLocation to create location “/Zettelkasten” & “/” & theYear & “/” & numMonth in theDatabase
– repeat with thisItem in theRecord
– set theResult to move record thisItem to theLocation
– end repeat
end if
set theRecord to import theTemplateFile placeholders thePlaceholders to the theLocation
end tell