Scripts Tab

This document first provides the background to Hook’s Script Editor. Then it describes the Script Editor itself.

Background to Script Editor

If your favorite app is not yet supported by Hook, you can use Hook’s Script Editor tab to copy and paste some AppleScript that does the trick. You can also press the “Update Built-in Scripts” button to get updated Scripts from CogSci Apps that might do the trick.

The Script Editor tab is for users who know AppleScript or JavaScript, or who wish to use AppleScript they receive from trusted sources. If you do not understand AppleScript, then do not use AppleScript unless it comes from a trusted source. (This recommendation applies also to Apple’s own Script Editor app, not just Hook). You can ask for input on the Hook Productivity forum.

Hook can interact with many, perhaps even most, supported apps without them having an entry in the ScriptEditor.

Hook assumes an app is either “read-only” or “create-read-write”.

Read-only apps include web browsers, ebook readers, mail apps, and PDF readers. Yes, you can create emails, but that is irrelevant to Hook at the moment because their ID is not known until the message is sent. And with the other “read-only” apps, 99.999% of the time, users are simply reading with them, not writing.

Create-read-write apps are apps that can appear in the “Hook to New” menu. Those are apps in which you can create new files or objects.

What Hook needs from apps

The primary function of Hook is linking, to do this Hook needs to be able to get the address (“URL” or “ID”) of the current app’s foreground resource. For example, to work with a web browser, Hook needs to be able to get the address of the web page (resource) in the frontmost window (or tab). This is the bare minimum requirement.

It is very helpful (but not strictly required) for Hook to be able to get the name of the frontmost window’s resource, so that Hook can insert this name in links that it creates (whether Hook formats those links in Markdown, RTF or for presentation in the Hook window).

What Hook needs to be able to create new items depends on the type of app.

a. If it is a file-based app, Hook just needs a template for the app to be in the templates folder. As explained on the Notes Tab preferences help page, “Hook to New” then copies that template into the new folder, renames the file, and links the file to the foreground resource.
b. For database apps, Hook needs to be able to tell the app to create a new resource. Either Hook will instruct the app about what address (URL or ID) the new resource should have, or the app will return the address of the new resource.

AppleScript requirements of third-party apps

Hook mainly uses AppleScript to interact with third party app. (For apps that lack the required AppleScript, like Firefox, Hook (also) does “UI scripting”, and may use other tricks.).

The AppleScript dictionary needs to support methods for the above. In sum, depending on the app, Hook may need a script (or standard macOS support) for

a. opening an item (for files a script is not required)
b. getting the name of the foreground item
c. getting the address of the foreground item
d. creating a new item (with the “Hook to New” command)

The Script Editor Tab Itself

This section describes the components of the Script Editor tab, and how to use them.

The Script Editor tab consists of several tabs in which you can

Apps pane (on left side of ScriptEditor tab)

The Apps pane presents a list of scriptable apps in your /Applications folder. The name and bundle of each app name are presented together. When you select an app in this pane, the Script Pane (on right) displays its content

Hook comes with built-in scripts for many apps. However, you can customize these scripts with the Script Editor tab (on the right). When you customize a built-in script, Hook places an asterisk (*) after their name.

The “Hide build-in scripts” checkbox (at bottom of the apps list) allows you to focus on scripts that you have customized. (For most users, there will be no customized scripts.)

The “Hide uninstalled apps” checkbox allows you to only see the apps that are in your /Applications folder.

Script Editor pane (on right)

The Script Editor pane consists of 4 tabs (at the top) and a text editor pane. There is a tab for each scriptable function, meaning :

a. opening an item (for files a script is not required)
b. getting the name of the foreground item
c. getting the address of the foreground item
d. creating a new item (with the “Hook to New” command)

Just click on the tab to get to the script you’d like to edit.

You will notice in perusing the built-in scripts that not all tabs require text. When text is not provided, Hook uses a default mechanism to interact with the app. For example, if it is a file-based app, then Hook will simply open the file using a system call.

Don’t forget to save a script bundle when you are ready to deploy it, using the “Save” button.

If you wish to revert to a built-in script, just click the “Revert to Built-in Script” button. So please feel free to experiment with scripts knowing that you can easily roll-back your changes.

NB: There will soon be an Export button so that you can save the selected script to a zip file.

Updating built-in scripts (bottom section)

Hook is capable of updating its scripts through communication with the Hook Productivity server. This update mechanism is separate from the process of updating the Hook app. This enables the updating of scripts to be more lightweight and frequent than updating the apps. However, when you update the app, you also get the latest scripts.

Three methods are available to update Hook scripts:

  1. using the Update Now button on the Script Editor pane,
  2. with the “Update Scripts during launch” checkbox on the Script Editor pane,
  3. by updating the entire Hook app.

If you edit a script or write your own custom scripts they will override Hook’s built-in scripts and will not be affected by any changes or updates. If you “Reset to Default” the scripts for an app, they will reset to the latest available version.

At the bottom of the Script Editor pane, there is a label that indicates the date and time at which Hook’s scripts were last synced from the server.

Updating of the app and scripts is subject to the same overall Hook license agreement.

URL Scheme

The scheme field must be filled in if there is an Open Item script. Hook matches the scheme to URLs to open links to an application with the right Open Item script.

If the application can handle the URL natively (website URLs, Omnifocus and other applications which support URL schemes) then it doesn’t need an Open Item script and doesn’t need the scheme to be filled out.

The scheme is used to find the appropriate script to open URLs with.

Scheme should match the URL returned by Get Address which is formatted scheme://document-identifier .