Open the preferences of Hook, click on the “Scripts” tab and then open the “New Item”.
Paste this into the script window:
use AppleScript version "2.4" -- Yosemite (10.10) or later
use scripting additions
use framework "Foundation"
tell application id "Cere"
if (count of documents) is equal to 0 then
return "No document is available"
end if
set openFile to file of front document
if openFile is missing value then
return "Hook can't link unsaved files"
end if
set filePath to my encodedPath(POSIX path of (openFile as alias)) as string
tell front document
if not (exists note "Inbox") then make new note with properties {name:"Inbox"}
set theContainer to note "inbox"
set myNote to make new note with properties {name:"$title"} at theContainer
end tell
set tinderboxURL to value of attribute "NoteURL" of myNote
set tinderboxURL to (text (1 + (length of "tinderbox://")) thru -1 of tinderboxURL)
set tinderboxURL to "tbx://" & tinderboxURL
return tinderboxURL & "?filepath=" & filePath
end tell
-- 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
And now try it out - have a saved TBX file open. Now go to Safari and open hook (ctrl+H). Next go to “Hook to new” in the menu of hook:
Select Tinderbox in the list of apps and Hook will create a new note within an “inbox” container in your TBX file.