# Hookmark Script for Obsidian
## Metadata
**Status**:: #x
**Zettel**:: #zettel/permanent
**Created**:: [[2022-10-05]]
**Topic**:: [[♯ Hookmark]]
**Parent**:: [[♯ Obsidian]]
## Get Address
Modified to include only the file base name.
```applescript
set myURL to "obsidian://hook-get-address"
set myScript to "open '" & myURL & "'"
do shell script myScript
delay 0.4
repeat 50 times -- poll clipboard for ~2.5 seconds
try
if (the clipboard) is not equal to "" then
exit repeat
end if
end try
delay 0.05
end repeat
set theResult to (get the clipboard)
set prevDelimiter to AppleScript's text item delimiters
set AppleScript's text item delimiters to {"file="}
set theParts to every text item of theResult
set AppleScript's text item delimiters to {"%2F"}
set theRemainingParts to every text item of the last item of theParts
set theResult to (first item of theParts) & "file=" & (last item of theRemainingParts)
set AppleScript's text item delimiters to prevDelimiter
return theResult
```
## New Item
Place new notes in folder `dock/`.
```applescript
set title to "$title"
set theURL to "$user_link"
set AppleScript's text item delimiters to {":///", "://"}
set theProtocolAndRemaining to every text item of theURL
set theProtocol to the first item of theProtocolAndRemaining
set theSource to the last item of theProtocolAndRemaining
if theProtocol is not "http" and theProtocol is not "https" then
set AppleScript's text item delimiters to {":"}
set theSource to theProtocolAndRemaining as string
end if
set AppleScript's text item delimiters to {"?", "#", "/"}
set theSource to the first text item of theSource
set filePath to do shell script "python -c \"import urllib, sys, re; print(urllib.quote(re.sub(r'[\\[\\]\\'?*#:||,\\/:\\\" ]+', ' ', sys.argv[1]).strip(), safe=''))\" " & quoted form of title
set titleLine to do shell script "python -c \"import urllib, sys; print(urllib.quote('# ' + sys.argv[1] + '\\n\\n#from/hook\\n\\n[' + sys.argv[2] + '](' + sys.argv[3] + ')', safe=''))\" " & quoted form of title & " " & quoted form of theSource & " " & quoted form of theURL
set newURL to "obsidian://new?vault=Brain&file=dock%2F" & filePath & "&content=" & titleLine
set openURL to "obsidian://open?vault=Brain&file=" & filePath
tell application "Obsidian"
activate
open location newURL
end tell
return openURL
```