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:
- The hooked item now has the Tana icon, instead of the default browser’s icon;
- 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 & ")"