Obsidian Hook to New

Considering the date string conversion method by @stevelw used in the following post: Add date to Fantastical title - Share your Hook scripts - Hook Productivity Forum, I have modified/combined the scripts provided also by @stevelw for achieving the desired result.

The complete script with the Zettelkasten suffix is as follows:

set tag to "from-Hook"
set linkToParent to "$user_link"

set theDate to (current date)
set theYearString to year of theDate as text
set theMonthString to (month of theDate as integer) as string
if (the length of theMonthString is 1) then set theMonthString to "0" & theMonthString
set theDayString to day of theDate as text
if (the length of theDayString is 1) then set theDayString to "0" & theDayString

set theHourString to hours of theDate as text
if (the length of theHourString is 1) then set theHourString to "0" & theHourString
set theMinuteString to minutes of theDate as text
if (the length of theMinuteString is 1) then set theMinuteString to "0" & theMinuteString

set theDateString to theYearString & theMonthString & theDayString & theHourString & theMinuteString

set title to "$title" & " - " & theDateString
set encodedTitle to do shell script "python -c \"import urllib, sys; print (urllib.quote(sys.argv[1]))\" " & quoted form of title
set encodedTitleWithAllowedCharacters to findAndReplaceInText(encodedTitle, "%20", " ")
set encodedTitleWithAllowedCharacters to findAndReplaceInText(encodedTitleWithAllowedCharacters, "%E2%80%94", "—")
set doubleEncodedTitle to do shell script "python -c \"import urllib, sys; print (urllib.quote(sys.argv[1]))\" " & quoted form of encodedTitleWithAllowedCharacters

set template to "---" & return & "title: " & title & return & return & "tags: ['#" & tag & "']" & return & return & "created at: '" & theDateString & "'" & return & "completed at: " & return & "modified at: " & return & "---" & return & return & "# " & title & return & return & "The following summary is mainly based on [" & title & "](" & linkToParent & ")." & return & return & "# Note" & return & return & return
set encodedTemplate to do shell script "python -c \"import urllib, sys; print (urllib.quote(sys.argv[1]))\" " & quoted form of template

set obsidianURL to "obsidian://new?name=" & doubleEncodedTitle & "&content=" & encodedTemplate
set myScript to "open " & quoted form of obsidianURL
do shell script myScript

delay 0.2

-- presere clipboard as Obsidian will put the note's link there
set originalClipboard to the clipboard
set the clipboard to ""

set myScript to "open " & quoted form of "obsidian://hook-get-address"
do shell script myScript

delay 0.2

set childMarkdownLink to the clipboard
set the clipboard to originalClipboard

set AppleScript's text item delimiters to "]("
set theItems to every text item of childMarkdownLink
set AppleScript's text item delimiters to ""
set childLink to text 1 thru -2 of the last item of theItems

return childLink
on findAndReplaceInText(theText, theSearchString, theReplacementString)
                set AppleScript's text item delimiters to theSearchString
                set theTextItems to every text item of theText
                set AppleScript's text item delimiters to theReplacementString
                set theText to theTextItems as string
                set AppleScript's text item delimiters to ""
                return theText
end findAndReplaceInText

The content of the generated note Obsidian Hook to New - Share your Hook scripts - Hook Productivity Forum - 202108241932.md is as follows:

---
title: Obsidian Hook to New - Share your Hook scripts - Hook Productivity Forum - 202108241932

tags: ['#from-Hook']

created at: '202108241932'
completed at: 
modified at: 
---

# Obsidian Hook to New - Share your Hook scripts - Hook Productivity Forum - 202108241932

The following summary is mainly based on [Obsidian Hook to New - Share your Hook scripts - Hook Productivity Forum - 202108241932](https://discourse.hookproductivity.com/t/obsidian-hook-to-new/3510/5).

# Note



4 Likes