For reference, AppleScript equivalents (using the Foundation classes for url encoding and decoding) might look something like:
Get Address
(copy whole script, down to end encodedPath)
use AppleScript version "2.4"
use framework "Foundation"
use scripting additions
on run
tell application "Tinderbox 8"
set ds to documents
if 0 < length of ds then
set doc to item 1 of ds
set oFile to file of doc
if missing value is not oFile then
set fp to my encodedPath(POSIX path of (oFile as alias)) as string
set oNote to selected note of doc
if missing value is not oNote then
set noteURL to (value of (attribute "NoteURL" of oNote)) as string
set strURL to (text (1 + (length of "tinderbox")) thru -1 of noteURL)
"[" & name of oNote & "](" & "tbx" & strURL & "?filepath=" & fp & ")"
else
""
end if
else
"[Hook can't link an unsaved file]()"
end if
else
""
end if
end tell
end run
-- GENERIC
-- https://github.com/RobTrew/prelude-applescript
-- encodedPath :: FilePath -> Percent Encoded String
on encodedPath(fp)
tell current application
(its ((NSString's stringWithString:fp)'s ¬
stringByAddingPercentEncodingWithAllowedCharacters:(its NSCharacterSet's ¬
URLPathAllowedCharacterSet))) as string
end tell
end encodedPath
Open Item
(Copy whole script, down to end splitOn)
use framework "Foundation"
use scripting additions
on run
set xs to splitOn("?filePath=", "$0")
set ys to splitOn("//", item 1 of xs)
tell application "Tinderbox 8"
activate
open (my decodedPath(item -1 of xs))
open location ("tinderbox://" & (item 2 of ys))
end tell
end run
-- GENERIC
-- https://github.com/RobTrew/prelude-applescript
-- decodedPath :: Percent Encoded String -> FilePath
on decodedPath(fp)
tell current application
(its ((NSString's stringWithString:fp)'s ¬
stringByRemovingPercentEncoding)) as string
end tell
end decodedPath
-- splitOn :: String -> String -> [String]
on splitOn(pat, src)
set {dlm, my text item delimiters} to ¬
{my text item delimiters, pat}
set xs to text items of src
set my text item delimiters to dlm
return xs
end splitOn