You can automate Hook using Apple’s Shortcuts app. Hook has an extensive list of actions with which you can copy links to the active window, add bookmarks to Hook, focus on a given bookmark, hook bookmarks together, and get your bookmarks. The uses of these actions are unlimited. They mean you can connect, create and access information anyway you like without even interacting with Hook’s user interface.
Check out our directory of Hook Shortcuts . They use Hook’s actions. These include Shortcuts we have created, and will include Shortcuts others have donated.
Shortcuts integration requires at least macOS 12 (Monterey) and Hook Pro version 3.8.
New to Shortcuts?
You can think of Hook’s actions, which are displayed in macOS Shortcuts app (and described below), as an “API” (application programming interface) to control Hook. It is equivalent to Hook’s AppleScript dictionary.
You can think of individual shortcuts as being user-friendly scripts, or “workflows”. In fact, Apple’s Shortcuts app is based on a product called “Workflows” that Apple acquired.
Hook’s Shortcuts Actions
A. Hook’s objects:
B. Hook’s actions:
A. Hook Objects
Many Hook actions operate with
Bookmark objects. These are links that can be stored in Hook. A Bookmark has the following fields.
- a name
- an address (URL) and
- optionally a path. The path parameter is used specifically when the URL matches the
hook://file/pattern. (I.e., its scheme is
hookand the “subscheme” is “file”).
2. Request Handle
Request Handle is an object returned by Get bookmark from active window when the foreground app cannot immediately return the address (URL) and name of the foreground item. This is typically because the foreground app uses x-callback-url, an asynchronous protocol, rather than AppleScript. So an action cannot immediately get the bookmark; a two-step process is required.
The request handle may be used as input parameter to Hook’s
Get Bookmark By Request Handle action.
B. Hook Actions
Action 1: Add Bookmark
Adds a bookmark to Hook with the given URL and name. If the name is not provided, the URL will be used as a name. If the URL is already in the database Hook will not add a bookmark. Thus (exceptions aside) this action returns a new or existing bookmark for the given URL. This means this action can be used as a “get bookmark” method (one that also can add a bookmark). However, this action cannot (yet) be used to change the name of an existing bookmark; thus, if a bookmark already exists for this URL, the name input parameter of this action will be ignored.
To be clear: also use this action whenever you want to get a Hook bookmark for a given URL. You can then feed this bookmark object into other actions.
- URL: a valid bookmark URL
- Title: a non-empty title of a bookmark
- A bookmark object
Invalid sub-scheme. hook://file/ URLs are not supported by Shortcuts. If user tries to add a bookmark of the form
hook://file/, Hook will return this message.
Action 2: Get Bookmark From Active Window
Returns a complex object containing either a valid bookmark or a request handle, and a value indicating the type of result that is returned.
Returns an object with three three fields:
bookmark: a bookmark object;
request handle: a string to be used in
Get bookmark by request handleaction;
is bookmark, a boolean value that indicates whether a bookmark object or a request handle is valid.
is bookmark is true (1), then the
bookmark field is valid, and the
request handle field should be ignored.
is bookmark is false (-1), then the
bookmark field is invalid, and the
request handle may be used to obtain a bookmark. If
is bookmark is false (-1) then in order to get the bookmark from the active window, use Hook’s
Get Bookmark By Request Handle with
request handle as input parameter.
The two step-process is required for apps that use asynchronous protocols (like x-callback-url) for inter-app communication. Example: Agenda, Craft, Drafts, and Obsidian. However don’t need to concern yourself about this implementation detail ( x-callback-url), simply use the
is bookmark value when appropriate.
is bookmark is true then if the item is not yet bookmarked, Hook will bookmark it in the process, meaning it will add the bookmark to its database.
⚠️ After calling
Get Bookmark From Active Window wait for 1s between calling
Get Bookmark By Request Handle. This will give time for the x-callback-url app to return its result to Hook, and available to you.
Action 3: Get Bookmark By Request Handle
request handle (which was returned by the prior
Get bookmark from active window action), return a bookmark. I.e. return a bookmark for the item that was in active window last time the
Get Bookmark From Active Window action returned a request handle.
NB: this is typically a bookmark for an app that uses x-callback-url.
request handle, as described in
Get bookmark from active window.
If there’s no request handle, an error message will be returned accordingly.
Action 4: Focus On Bookmark
Open Hook and focus on the given bookmark. That means Hook’s title bar will show the title of the bookmark, and its hooked items will be presented in the HOOKED section. However, if the bookmark already exists in Hook the name will be ignored.
- a bookmark
An error message will be return if bookmark is missing or invalid.
Action 5: Hook Bookmarks Together
Hook two bookmarks given together.
- bookmark 1
- bookmark 2
Error messages: If the input is not a valid URL Hook will say
Input to bookmark1 is not a valid bookmark
Input to bookmark2 is not a valid bookmark
Action 6: Get Bookmarks Hooked To URL
Get a list containing all the bookmarks that are hooked to the URL.
- URL: URL of the bookmark.
Result: a list of bookmarks that are hooked to the given URL.
If there is no URL, Hook will ask for a valid URL.
Action 7: Unhook Bookmarks
Unhook the two given bookmarks from each other. This does not delete the bookmarks.
- bookmark 1: first bookmark
- bookmark 2: second bookmark