√ Craft and Hook compatibility

Starting from next version (coming around 18th Jan) this script will work for Craft :
//START///
click menu item “Copy Markdown Deeplink” of menu 1 of menu bar item “File” of menu bar 1
delay 0.05
repeat 50 times – poll clipboard for ~2.5 seconds
try
if (the clipboard) is not equal to “” then
exit repeat
end if
end try
delay 0.05
end repeat
set theLink to the clipboard
return theLink
end tell
//END///

Welcome to the Hook Productivity Forum , @balint. I’m delighted by the direction of Craft.

UI Scripting is a good first start. However,

UI scripting is not reliable, it requires translations. And if the UI of the app changes (e.g., you move the Copy Link menu items around), then the scripts will break. It would be better to have an API ( AppleScript/ JavaScript or a command line interface ) or x-callback-url.

It is also helpful to to support “new item” per point #4 of Creating and Modifying Integration Scripts – Hook. (See also Hook to Copied Link. That would enable users to automatically link items in other apps to new Craft documents/notes. That’s very helpful for note-taking (e.g., if the user is reading a PDF, spreadsheet or webpage, in any linkable app, the user could then do Hook to New > Craft. That gives them a new craft note that has been named, stored , and linked … in one operation). So the new item x-callback-url, for instance, would take the name of the item as a parameter, and Craft would return the URL of the newly created Craft note.

Once you have the automation in place, we CogSci Apps can write the integration scripts.

1 Like

UI Scripting is also slower than an API.

Thanks, succesfully implemented x-callback-url. Can you point me to what format Hook is expecting - or alternatively a sample script utilizing x-callback-url I can take and modify?

2 Likes

Well this more than anything else has convinced me to give Craft a try! Way to be a team player @balint!

1 Like

Awesome!!!

New item

Hook’s current New Item script for the Drafts app is a good example of x-callback-url usage by Hook.
Hook uses Draft’s x-callback-url 's in it’s New Item script (which is used by the Hook to New > Drafts command).

The conforming app’s x-callback-url for New Item needs to take a name (title) string as input, and return the address, that’s all. Hook is not fussy about the specific API. The method can return more than is needed. (Drafts’ API is quite generous, providing information Hook need not use, and that’s fine). Hook will then create a new bookmark for the item, caching that name (updating as necessary in the future), and it will use the URL to open the bookmark going forward.

There’s also this example: Hook to New with Momenta’s Agenda app using x-callback-url – Hook

Get Address

Drafts recently added an x-callback-url Hook can use in its Get Address tab. However, Hook has not yet been updated for this. It was / is , coincidentally, the next item on our integration update list. We hope to publish an update tomorrow on the forum.

Get Name

Get Name is mostly for legacy purpose. The Get Address command can be used to return both the address and the name of the item, in Markdown format (for convenience).

Hook’s integration documentation updates

We will soon update our Integration: How Hook Works with Your Favorite Apps – Hook, improving our examples. It would make sense for us to use Craft and Drafts as examples in our Help pages.

I should point out that if the app contains an API to insert hypertext, then on Hook to New, Hook would insert a linkback to the new Crafts doc, like it does for

  • Drafts
  • OmniFocus
  • Apple Notes

this is particularly handy for iOS apps, so that users can get the benefit of links there too.

That’s also something we’ll add to the updated integration documentation.

1 Like

Awesome, exciting!! I’m really starting to “get it” finally.

1 Like

There are two patterns of Get Address scripts for Hook that are based on x-callback-url. This post illustrates each with Draft. The first way uses the third-party app’s x-callback-url that returns the URL and title of the current item (and possibly other info which Hook would likely ignore). The second uses the third-party app’s x-callback-url method that returns the UUID and title of the current item.

Hook defines names to represent the name of the key in the key-value pair returned by the third party app’s x-callback-url. They are:

  1. urlkey: the name of the key in the URL key-value pair (i.e., for obtaining the URL of the current item)
  2. identifierKey: the name of the key in the UUID key-value pair (i.e., for obtaining the UUID of the current item)
  3. titleKey: the name of the key in the title key-value pair (i.e., for obtaining the title of the current item)

Hook’s Get Address script for an app needs to set (1) or (2), and (3). The first is preferred (the URL). (If the name is not set in (3) it can be set in the Get Name script, but it’s preferable to leave the Get Name script blank.)

Here are two examples of Get Address for Drafts app using Drafts getCurrentDraft URL Schemes :

  1. This one uses urlkey (and titleKey, of course):

    set callbackURL to “hook://x-callback-url/currentlink”

    set callbackURL to callbackURL & “?” & “%26urlkey=url%26titleKey=title”

    set myURL to “drafts://x-callback-url/getCurrentDraft?text=” & “&x-success=” & callbackURL

    set myScript to “open '” & myURL & “’”
    do shell script myScript

  2. This one uses identifierKey (and titleKey, of course):

    set callbackURL to “hook://x-callback-url/currentlink”
    set partialURL to “drafts5://x-callback-url/open%3Fuuid%3D”

    set callbackURL to callbackURL & “?%26identifierKey=uuid%26titleKey=title%26partialURL=” & partialURL

    set myURL to “drafts://x-callback-url/getCurrentDraft?text=” & “&x-success=” & callbackURL

    set myScript to “open '” & myURL & “’”
    do shell script myScript

The above scripts require Hook 2.2.1 which will be released shortly, and which has extra code for handling x-callback-url -baed Get Address scripts.

Basically, Hook just needs the URL and title of the currently selected item. Some apps just return an ID and title; Hook can create a URL using the ID (case 2). As long as the app developer provides the x-callback-url (or AppleScript or whatever API) we ( CogSci Apps) can normally write Hook’s scripts to integrate with it.

Awesome, can’t wait for 2.2.1!

1 Like

Sorry to be a pest, but any update on the timeline here? I…uhhh…got a little excited and broke my Drafts integration script and was hoping to just hit “update” before too long! :slight_smile:

My initial thought about this on Tue was Thu (today) as ETA. But I’ve learned the hard way that making ETA predictions is risky. (I don’t know how Apple has managed to stick to its yearly pace all these years. It is truly remarkable.) It’s not just a script, but there’s a core change under the hood to handle the callback. We need to put it through code review and QA, and potentially iterate. QA for an app like is very time consuming. Then there’s customer documentation. Having said that, I hope we can release it this week-end.

2 Likes

Sweet, thanks for the update!

1 Like

unfortunately, that’s now looking unlikely. I’ll keep you posted.

1 Like

Any update here? Just checking before I revert my Drafts scripts… :wink:

Testing is in the works and hopefully released this evening or Wed morn.

1 Like

Sorry, but we have more delays with 2.2.1 … can’t provide a more specific ETA than ASAP , unfortunately.

No worries, we can wait! It’ll be worth it too.

1 Like

Hook version 2.2.1 is now available . This includes ability to put x-callback-url in Get Address, which is illustrated in Using Hook with Drafts.

    set callbackURL to "hook://x-callback-url/setCurrentNode"

set myURL to "drafts://x-callback-url/getCurrentDraft?" & "&x-success=" & callbackURL

set myScript to "open '" & myURL & "'"

do shell script myScript
return callbackURL

In our testing, the above Drafts “Get Address” script works in Big Sur but not in macOS 10.14, so we didn’t make it the default integration with Drafts. I don’t know if that’s a Drafts issue or a Hook issue — we’ll need to look into it.

Hi again, in case you haven’t seen it, Hook version 2.2.1 is now available - Releases - Hook Productivity Forum. I hope this helps.

1 Like