Obsidian Hook to New

I didn’t like the messy titles this produced, so I updated the script to encode the title (to make sure it’s file system safe) and then reinstate some common characters known to be file safe. You can easily add more replacement lines for other characters you don’t want encoded.

…
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 & "tags: [" & tag & "]" & return & "---" & return & "# " & title & return & return & "Parent: [" & title & "](" & linkToParent & ")" & return & return
…
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
2 Likes