# Problem Hooking Items via AppleScript

**URL:** https://discourse.hookproductivity.com/t/problem-hooking-items-via-applescript/3577
**Category:** Discussion & Help
**Created:** [August 6, 2021, 8:57pm UTC](https://discourse.hookproductivity.com/t/problem-hooking-items-via-applescript/3577 "2021-08-06T20:57:08Z")
**Posts on this page:** 11
**Page:** 1

<div class="post-metadata">

### Author: ![GadgetComa](https://discourse.hookproductivity.com/user_avatar/discourse.hookproductivity.com/gadgetcoma/32/1706_2.png) [@GadgetComa](https://discourse.hookproductivity.com/u/GadgetComa)
#### Post date: [August 6, 2021, 8:57pm UTC](https://discourse.hookproductivity.com/t/problem-hooking-items-via-applescript/3577/1 "2021-08-06T20:57:08Z")

</div>

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:

```auto
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

---

<div class="post-metadata">

### Author: ![stevelw](https://discourse.hookproductivity.com/letter_avatar_proxy/v4/letter/s/ea666f/32.png) [@stevelw](https://discourse.hookproductivity.com/u/stevelw)
#### Post date: [August 7, 2021, 5:35am UTC](https://discourse.hookproductivity.com/t/problem-hooking-items-via-applescript/3577/2 "2021-08-07T05:35:32Z")

</div>

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

---

<div class="post-metadata">

### Author: ![GadgetComa](https://discourse.hookproductivity.com/user_avatar/discourse.hookproductivity.com/gadgetcoma/32/1706_2.png) [@GadgetComa](https://discourse.hookproductivity.com/u/GadgetComa)
#### Post date: [August 7, 2021, 1:45pm UTC](https://discourse.hookproductivity.com/t/problem-hooking-items-via-applescript/3577/3 "2021-08-07T13:45:34Z")

</div>

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

---

<div class="post-metadata">

### Author: ![GadgetComa](https://discourse.hookproductivity.com/user_avatar/discourse.hookproductivity.com/gadgetcoma/32/1706_2.png) [@GadgetComa](https://discourse.hookproductivity.com/u/GadgetComa)
#### Post date: [August 7, 2021, 3:00pm UTC](https://discourse.hookproductivity.com/t/problem-hooking-items-via-applescript/3577/4 "2021-08-07T15:00:20Z")

</div>

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:

```auto
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:

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

```

---

<div class="post-metadata">

### Author: ![GadgetComa](https://discourse.hookproductivity.com/user_avatar/discourse.hookproductivity.com/gadgetcoma/32/1706_2.png) [@GadgetComa](https://discourse.hookproductivity.com/u/GadgetComa)
#### Post date: [August 7, 2021, 3:27pm UTC](https://discourse.hookproductivity.com/t/problem-hooking-items-via-applescript/3577/5 "2021-08-07T15:27:16Z")

</div>

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

---

<div class="post-metadata">

### Author: ![stevelw](https://discourse.hookproductivity.com/letter_avatar_proxy/v4/letter/s/ea666f/32.png) [@stevelw](https://discourse.hookproductivity.com/u/stevelw)
#### Post date: [August 7, 2021, 10:11pm UTC](https://discourse.hookproductivity.com/t/problem-hooking-items-via-applescript/3577/6 "2021-08-07T22:11:54Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![LucB](https://discourse.hookproductivity.com/user_avatar/discourse.hookproductivity.com/lucb/32/2228_2.png) [@LucB](https://discourse.hookproductivity.com/u/LucB)
#### Post date: [August 7, 2021, 10:48pm UTC](https://discourse.hookproductivity.com/t/problem-hooking-items-via-applescript/3577/7 "2021-08-07T22:48:05Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![GadgetComa](https://discourse.hookproductivity.com/user_avatar/discourse.hookproductivity.com/gadgetcoma/32/1706_2.png) [@GadgetComa](https://discourse.hookproductivity.com/u/GadgetComa)
#### Post date: [August 8, 2021, 12:58am UTC](https://discourse.hookproductivity.com/t/problem-hooking-items-via-applescript/3577/8 "2021-08-08T00:58:38Z")

</div>

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

---

<div class="post-metadata">

### Author: ![LucB](https://discourse.hookproductivity.com/user_avatar/discourse.hookproductivity.com/lucb/32/2228_2.png) [@LucB](https://discourse.hookproductivity.com/u/LucB)
#### Post date: [August 18, 2021, 4:05am UTC](https://discourse.hookproductivity.com/t/problem-hooking-items-via-applescript/3577/9 "2021-08-18T04:05:47Z")

</div>

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

---

<div class="post-metadata">

### Author: ![LucB](https://discourse.hookproductivity.com/user_avatar/discourse.hookproductivity.com/lucb/32/2228_2.png) [@LucB](https://discourse.hookproductivity.com/u/LucB)
#### Post date: [August 18, 2021, 5:12am UTC](https://discourse.hookproductivity.com/t/problem-hooking-items-via-applescript/3577/10 "2021-08-18T05:12:24Z")

</div>

[Hook 3.2.1 is available (4468; Integration v. 174) - Releases - Hook Productivity Forum](https://discourse.hookproductivity.com/t/hook-3-2-1-is-available-4468-integration-v-174/3630)

---

<div class="post-metadata">

### Author: ![GadgetComa](https://discourse.hookproductivity.com/user_avatar/discourse.hookproductivity.com/gadgetcoma/32/1706_2.png) [@GadgetComa](https://discourse.hookproductivity.com/u/GadgetComa)
#### Post date: [August 18, 2021, 1:40pm UTC](https://discourse.hookproductivity.com/t/problem-hooking-items-via-applescript/3577/11 "2021-08-18T13:40:08Z")

</div>

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