Using Applescript to hook items together

Hey guys,

I’ve created an automation via Keyboard Maestro and AppleScript that will create a folder, an Obsidian note and a Things project.

I’m able get URLs to the Obsidian note and Things project, as well as the POSIX path to the New Folder.

Even possessing all this information, I’m still not able to figure out how to use AppleScript to make the final touch to this automation: hooking all those items together. Any hints?

Here’s an example. Replace /Users/lucb/tmp/test3.txt with any path.

  tell application "Hook"
	set myURL to ""
	set myBookmark to make bookmark with data myURL
	set myBookmark2 to make bookmark with properties {name:"test", address:"/Users/lucb/tmp/test3.txt"}
	hook myBookmark and myBookmark2
end tell

Updated 2021-01-19 13:39: I simplified it.


Hey @LucB, many thanks for that!

I’ve implemented your script with a simple dummy variables and it seems to work just fine.

I wonder if there’s room for a couple of improvements, though:

Bidirectional links to 3+ items

I’ve managed to do it by using 3 lines of code (see bellow) is there a way to do so in just one?

-- Dummy variables
set clientName to "Testing"
set clientPath to "/Users/lucasgalvaodebritto/Desktop/Testing"
set thingsLink to "things:///show?id=8GR33M86DMcXQWuDd5v4r6"
set myURL to ""

-- Logic
tell application "Hook"
	-- Create bookmarks
	set myBookmark to make bookmark with data myURL
	set myBookmark2 to make bookmark with properties {name:nomeCliente, address:pathCliente}
	set myBookmark3 to make new bookmark with data tLink
	-- Hook'em up (is there a better way?)
	hook myBookmark and myBookmark2
	hook myBookmark2 and myBookmark3
	hook myBookmark and myBookmark3
end tell

Names for links

The resulting hook for the Testing folder was lacking the names for the hooked items, like this:

Captura de Tela 2021-01-20 às 11.11.22

I wonder if there’s a way to have the names of the hooked items update themselves or should I always declare them on my script via the name property of the bookmark object?

to have them show up initially they need to be configured in the script . Hook has no way of knowing the value of the title of an item until it is invoked on an item. When Hook is invoked on an item, it will update the title of the item automatically unless it has been renamed manually in Hook’s user interface. (You can also reset the name from the interface to its original value.) Currently the rename commands are only in the Link menus. But we plan to replicate them wherever items are referenced in Hook.

1 Like