Improvement to "Tana" app script; hooked item now opens in the designated app

Support for the Tana Desktop app was recently added in Scripts v322. The script hooks Tana “nodes”, returning the node title and node web URL to Hookmark.

The URL it emits contains the https: protocol handler, even though the Tana Desktop app has its own protocol handler registered (tana://). This is because the Tana command leveraged by the script returns the URL in a form designed for sharing on the web. However, the Tana Desktop app itself supports “deep linking”, using the dedicated protocol handler and a slightly different URL structure.

Here is an improvement to the script that replaces the https: URL - which would cause the hooked item to be opened in a web browser - with a tana: URL that will open in the Desktop app - the same app that was hooked from originally.

This is an improvement, because:

  1. The hooked item now has the Tana icon, instead of the default browser’s icon;
  2. The hooked item now deep-links into the Tana desktop app that the Hookmark user originally hooked from; it is my opinion that this is a much better user experience, and in fact is the experience that any Hookmark user would expect.

The only diff is the last 10-ish lines; please consider this submission. Thanks!

-- set "Copy Link(HTML formmated)" shortcut to control+command+C
set the clipboard to ""
delay 0.2

tell application "System Events" to tell process "Tana"
	keystroke "c" using {control down, command down}
	delay 0.2
	repeat 10 times -- poll clipboard for ~1 seconds. Sometimes set x to the clipboard throws exception
		try
			set theURL to the clipboard
			if theURL is not equal to "" then
				exit repeat
			end if
			
		end try
		delay 0.1
	end repeat
	set AppleScript's text item delimiters to " ("
	set theTextItems to every text item of theURL
	
	set theURL to last item of theTextItems
	set theTitle to theTextItems's (items 1 thru -2)
	
	set AppleScript's text item delimiters to ""
	set theTitle to theTitle as string
	set theURL to text 1 thru -2 of theURL
	
end tell
-- Mangle the https URL for Tana's protocol handler/app structure:
-- old: `https://app.tana.inc?nodeid=ABCD1234`
-- new: `tana://node/ABCD1234`
set AppleScript's text item delimiters to "https://app.tana.inc?nodeid="
set the item_list to every text item of theURL
set AppleScript's text item delimiters to "tana://node/"
set newURL to the item_list as string
set AppleScript's text item delimiters to ""

return "[" & theTitle & "](" & newURL & ")"
2 Likes

Just a note; I was working on this myself, but my implementation tried to send keystrokes into Tana Desktop to reproduce the same functionality the original script author used. It only worked 75% of the time. So I just want to give some kudos to whomever that author is; leaning on a keyboard shortcut defined inside Tana app is a much, much better idea, that key insight was a flash of brilliance and I just want them to know that somebody noticed :smile: .

2 Likes

Good job! It works nice so far. I’m seriously considering moving from Roam Research to Tana because of the deep link feature provided by Hookmark and you right now. I wonder if there’s way to invoke Hook in Roam’s Desktop app?

1 Like

Thank you very much for your contribution to Hookmark, @threecheese . It is a great improvement!

1 Like

I have not checked Roam’s desktop app, I am in the middle of a migration from Roam to Tana. The biggest negative for Tana is it is very difficult to get data out of it from outside the app. It supports pushing data - you can create and run a command on any node that will push that node’s content out - or run the built-in “export” command, and they have an API for bringing data in, but that’s about all.
Other negatives include:

  • Not local-first, all data is stored in Firebase
  • No mobile app yet, but they say it’ll be released in Q3 probably, but their mobile capture app is fantastic as it supports typing, images, video, voice-to-text, and OCR
  • Difficult to hack, unlike Roam where you can do whatever you want with CS/JS/Datalog etc.
  • No Markdown :frowning:

That all being said, Tana is unlike any app I’ve ever used, and their model is pretty brilliant. The best parts of a block-based editor and a database squooshed together, and the structuring it permits has solved my biggest Roam gripe - which is that it doesn’t scale information in a way that works for my brain. My Roam database is a JUNGLE :slight_smile:

Thanks for your introduction!
Actually I’ve used Roam Research and Tana for quite a while. For me they have different personalities, I feel like much easier to write things done and really to think in Roam. There are more distractions in Tana and I think Tana focusing on getting organized more. (I don’t like to customize lots of stuff when using apps)
Anyway, Tana now has the ability to link to my local files and apps with Hookmark, so Tana will for sure be the best second brain over Roam for me. Your and Hookmark team’s efforts really influence my choice :grin: