Hook action for Tinderbox


after the Tinderbox-Hook zoom meeting today I would like to share my script to create a new note in TBX with the “Hook to new…” command. Just copy this under “Preferences/Scripts/New Item”:

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

is there a variable like $title (or any other option) to get the link of the copied target? I would like to add the link into an attribute in Tinderbox.

Welcome to the Hook Productivity Forum , @webline . And thanks for the above script. I tried quickly to make it work but had a glitch. Will revisit this on Monday.

These variables are available:

  1. $user_link: plain url
  2. $title: plain title

I don’t want to seem pushy but will Hook give me access to a selection made by the user when Hook was opened (for example a text selected in Safari) too?

1 Like


reason was that in my quick test I didn’t have a Tinderbox note open, which the script required.

Currently Hook only copies the selection in certain cases via a different command: Copy Selection and Link – Hook. That’s currently for PDF apps that support deep linking.

For copying in web browser there’s Hook’s share sheet: Access Hook Functions from the Share menu in Safari and Finder (macOS Share Sheets) – Hook, which exposes several commands including Copy Selection and Link.

We intend to open this up further.

Thanks again, @webline ! We’ve adapted this with minor changes (dialog box) in Hook integration. This leads to 2 dialog boxes at the moment. CogSci Apps will need to change something under the hood to prevent that.

Normally our integration scripts select /open the newly created item. The current version of the integration does not select the newly created note. I suppose Tinderbox’s AppleScript has a way to do that which we can address.

1 Like

I added one line of code to my version of the script:

set value of attribute "URL" of myNote to "$user_link"

I think this fits well to the way Tinderbox handles notes from external sources.

P.S.: if you like to show/open the new note in TBX a simple “activate” would do
tell application id "Cere" to activate

And you could store the path to a default file in the script and then use

	set theTBXFile to "/Users/myname/Documents/Tinderbox/sample.tbx"
	set theDialogText to "Store to your default file or the frontmost file?"
	display dialog theDialogText buttons {"Frontmost", "Default"} default button "Default" with icon caution giving up after 5
	if the button returned of the result is "Frontmost" then
		set theTarget to false
		set theTarget to true
	end if
	tell application id "Cere"
		if theTarget then
			open theTBXFile
		end if