Automation Documentation: Hooking Alfred Workflows09 Apr 2023
navigateto/. I have updated the script in this post to reflect this.
Last year I wrote several posts about using Hookmark (neé Hook) to link to automation documentation. At the time I was a little frustrated in that I had several complex Alfred workflows that I was unable to use Hookmark for to link back and forth between the workflow and the associated notes. However, Vitor of Running with Crayons replied recently to my feature request on the Alfred forums, and with the latest Alfred beta (v5.1 build 2130), I now have a working solution.
Adding a Script for Alfred Workflows to Hookmark
Adding scripts to Hookmark requires a pro subscription - specifying your own custom scripts being part of the automation feature set that is available to such subscribers. Moreover, adding an integration script for Alfred workflows ia a little bit trickier than usual as Alfred isn’t actually the app we want to add our script to. We actually want to add it to the Alfred Preferences app which is embedded inside the Alfred app.
- Open Hookmark.
⌘,to open Hookmark’s preferences window.
- Select the Scripts section.
- Select the
+in the bottom left to add a new entry to the list of apps.
⇧⌘Gto open the standard Finder path entry window.
- Enter in the following path:
/Applications/Alfred 5.app/Contents/Preferences/Alfred Preferences.app
This should give you an empty set of script options for Alfred Preferences (com.runningwithcrayons.Alfred-Preferences).
Add the Get Address Script
The script to add is for the Get Address. With this we’ll build a full Markdown link for accessing the workflow.
The script utilises three scripting languages. AppleScript is the language used by Hookmark, so the main ‘wrapper’ script is written in AppleScript and effectively just runs the two other scripts and outputs the final result.
The second script is a shell script, and this time it is reading information from a PLIST (property list) file. It uses the workflow ID to identify the correct PLIST file and then gets the name of the workflow from it. Furnished with both the name and the workflow ID, the script then carries out a simple string concatenation to generate the desired Markdown link; which is then output by the main AppleScript script.
Copy and paste the script below into your Get Address section, click on Save, and Hookmark will be ready to link up your Alfred workflows.
let objApp = Application.currentApplication();
objApp.includeStandardAdditions = true;
// Return the latest workflow ID from Alfred's history file
JSON.parse(objApp.read(Path($.getenv('HOME') + '/Library/Application Support/Alfred/history.json'))).preferences.workflows;\"
set strWFLink to do shell script "
# Get Name
WFNAME=$(defaults read \"$HOME/Library/Application Support/Alfred/Alfred.alfredpreferences/workflows/" & strWFID & "/info.plist\" \"name\")
# Build URL to Open
WFLINK=\"alfredpreferences://navigateto/workflows>workflow>" & strWFID & "\"
# Output Markdown Link
Once again, my main aim was to be able to bidirectionally link to my relevant automation documentation within one of my Obsidian vaults. But where I utilise a web API, I can now link to API documentation, and for my workflows that are associated with a particular project (e.g. configuration of a local web site/server), I can link to relevant files, folders and site pages. Being able to link up my automations and documentation like this is a big time saver for me by helping to ensure everything is accessible. The less accessible my documentation is, the less likely I am to maintain it effectively, so this just smooths away that friction.
Hopefully, you can see a similar use for your own Alfred workflows with Hookmark.