Problem Hooking Items via AppleScript

I’m trying to link a DEVONthink item to an OmniFocus item via AppleScript, but when I try the hook command to hook the two bookmarks, I get an error that Hook can’t get bookmark id. What’s odd is that it’s always the second bookmark in the hook command that causes this error regardless of whether it’s DT or OF. In other words, with the item URL for my DT item in the variable dtLink and the task URL for the OF item in ofLink, I do the following:

tell application "Hook"
  set myBookmark to make bookmark with data dtLink
  set myBookmark2 to make bookmark with data ofLink
  hook myBookmark and myBookmark2
end tell

I get the error “can’t get bookmark id” followed by the link for myBookmark2. If I swap myBookmark and myBookmark2 in the hook command, I still get the error on the bookmark after the ‘and’.

What am I missing?

Thanks,

  • Leon

Not tried this myself, but my first debug would be to add a delay before the Hook — maybe the add bookmark command is asynchronous?

1 Like

Bingo! Great thinking. Thanks. It’s even more likely an issue on this M1 Mac given how darned fast it is. :wink:

I spoke to soon. It seems like the delay gets it to work occasionally, but it still fails most of the time. I’ve tried increasing the delay and adding delays after each hook command. Still no luck. I’ve trimmed down the code to the bare minimum to create an item in DEVONthink and OmniFocus without involving mail. It still fails. Here’s the simpler version:

tell application id "DNtp"
	set theRecord to create record with {name:"Test", type:txt}
	set theLink to the reference URL of theRecord
end tell

tell application "OmniFocus"
	tell default document
		set newTaskProps to {name:"Test"}
		set newTask to make new inbox task with properties newTaskProps
		set taskID to id of newTask
		set theTaskURL to "omnifocus:///task/" & taskID
	end tell
end tell

tell application "Hook"
	set myBookmark to make bookmark with properties {address:theLink, name:"Test"}
	set myBookmark2 to make bookmark with properties {address:theTaskURL, name:"Test"}
	hook myBookmark and myBookmark2
end tell

Here’s the error I get:

error "Hook got an error: Can’t get bookmark id \"omnifocus:///task/p8Zbd00NKPV\"." number -1728 from bookmark id "omnifocus:///task/p8Zbd00NKPV"

I bumped the delay to 10 and it seems to work consistently. Is there a better way?

1 Like

What if you skip the bookmark variables and put the bookmark lines inside the Hook line? That may force it to resolve both bookmarks before Hooking them.

Looking under the hood, we don’t think tinkering further with that AppleScript will do any good. we will further optimize the underlying automation engine in Hook 3.3, due hopefully early Sept. Thanks for all the feedback and sorry for the inconvenience.

Thanks @LucB. It’s not a huge inconvenience. Let me know if I can help troubleshoot further or test any changes.

1 Like

This problem is fixed in Hook Version 3.2.1 (4468; Integration v. 174) which we are in the process of releasing.

1 Like

Hook 3.2.1 is available (4468; Integration v. 174) - Releases - Hook Productivity Forum

1 Like

Fantastic. I removed the delay from my script and it works flawlessly. Thanks.

1 Like