Alfred - Slink for SearchLink

Welcome to this documentation page for Slink - a SearchLink workflow for Alfred, the popular launcher and automation application for macOS.

SearchLink is a macOS utility created by Brett Terpstra. It takes text and modifiers and will then attempt to identify a matching web page and replace the content with a URL or a type of Markdown link/reference.

Slink is an Alfred workflow that allows you to interact with, and utilise the SearchLink utility from within Alfred. When Brett created SearchLink, also created a script to let LaunchBar users take advantage of it from that launcher app. Not being a Launchbar user, when I started using SearchLink, I created something similar for Alfred users.

The workflow primarily acts as an Alfred intermediary to SearchLink, allowing you to enter or pass your search phrase into Alfred and automatically return some content without having to remember the specific SearchLink syntax.

Latest Version: 1.2.0

Prerequisites:

Functionality

Slink offers a handful of features and triggers.

Keyword Trigger: sl
External Trigger: sl
Snippet: Available
Triggering this flow will allow you to enter a search phrase into Alfred and pass that to SearchLink. Once the result has been returned, it can be found on the clipboard. There is a user configuration option that determines if the result is also automatically pasted to the current cursor position when Alfred disappears.

  • By default, the result will be a Markdown link.
  • Holding down COMMAND when the search is performed will force the result to be a URL.
  • Holding down CTRL will open the URL in the default web browser.
  • Any SearchLink syntax can be included to override the behaviour.

Keyword Trigger: slc
External Trigger: slc
Snippet: Available
Triggering this flow will allow you to enter a search phrase into Alfred and pass that to SearchLink. Once the result has been returned, it can be found on the clipboard.

  • By default, the result will be a Markdown link.
  • Holding down COMMAND when the search is performed will force the result to be a URL.
  • Holding down CTRL will open the URL in the default web browser.
  • Any SearchLink syntax can be included to override the behaviour.

Keyword Trigger: sli
External Trigger: sli
Snippet: Available
Triggering this flow will allow you to enter a search phrase into Alfred and pass that to SearchLink. Once the result has been returned, it can be found on the clipboard, and it will be pasted at the current cursor position when Alfred disappears.

  • By default, the result will be a Markdown link.
  • Holding down COMMAND when the search is performed will force the result to be a URL.
  • Holding down CTRL will open the URL in the default web browser.
  • Any SearchLink syntax can be included to override the behaviour.

Keyword Trigger: sle
External Trigger: sle
Snippet: Not Available
Triggering this flow will open the SearchLink configuration file for editing.

The text editor application used to edit the file is specified in the user configuration settings. It defaults to TextEdit.

Keyword Trigger: slcustom
External Trigger: slcustom
Snippet: Not Available
Triggering this flow will open a custom link configuration file for editing. The file is used by Slink (though could be used by othjer tools too) and not by SearchLink directly. It provides a way to override default results from SearchLink with specific results defined in the file.

The text editor application used to edit the file is specified in the user configuration settings. It defaults to TextEdit.

Keyword Trigger: slink
External Trigger: slink
Snippet: Available
Triggering this flow will list and allow the triggering of the other options. The available options are as follows:

  • Copy Markdown Link
  • Insert Markdown Link
  • Copy URL
  • Insert URL
  • Open URL
  • Edit SearchLink Configuration
  • Edit SearchLink Custom Link Data File

Triggers

There are a variety of ways to access different functionality included in Slink, including keyword triggers, hot keys, snippets, external triggers, and universal actions.

Keyword

Keyword triggers are text entered directly into the Alfred window to trigger a flow.

Keyword Functionality
sl Default Search
slc Copy Link
sli Insert Link
sle Edit SearchLink Configuration
slcustom Edit SearchLink Custom Link Data File
slink Slink

Hot Key

Hot keys can be used to trigger maby of the available flows in Slink.

The input used with the hot key depends upon the flow that is being triggered. It may trigger an action on the current text selection, prompt the user to enter the text in Alfred (as if they had triggered by keyword), or it may not require any input at all.

Functionality Input for the Flow
Copy Markdown Link Text selection in current application
Insert Markdown Link Text selection in current application
Copy URL Text selection in current application
Insert URL Text selection in current application
Open URL Text selection in current application
Default Search User enters into Alfred
Copy Link User enters into Alfred
Insert Link User enters into Alfred
Slink User enters into Alfred
Edit SearchLink Configuration None
Edit SearchLink Custom Link Data File None

Snippet

Snippets are entered into any text area and trigger a flow. Options to specify snippets for any of the following functionality are included in the Slink workflow:

Functionality
Default Search
Copy Link
Insert Link
Slink

External

External triggers can be used within any Alfred workflow to call a flow in Slink, or even externally through an AppleScript call or URL.

External Functionality
sl Default Search
slc Copy Link
sli Insert Link
sle Edit SearchLink Configuration
search Pass a string directly to SearchLink

Slink does not directly support all possible SearchLink syntax, particularly as you can define your own custom searches. However, you can pass in standard SearchLink syntax as part of your query, and you can always use add your own additions in your own workflow by utilising an external trigger in this workflow to receive that content.

The example available for download below allows you to trigger a search on selected text, limited to Wikipedia, that will replace that text with a Markdown link.

Universal Actions

Because SearchLink works exclusively on text, universal actions are only enabled for text input. They are not currently set to use files, and it would be illogical to search for a URL when given the URL.

Universal Action Functionality
SearchLink (Insert MD Link) Insert Markdown Link
SearchLink (Copy MD Link) Copy Markdown Link
SearchLink (Insert URL) Insert URL
SearchLink (Copy URL) Copy URL
SearchLink (Open) Open URL

Slink allows you to specify a file of data to override the use of SearchLink. This is what you might get from using a text expansion utility for specific links, and using a snippet to trigger the insertion of the URLs or Markdown links. Using Slink to do this means you have to select the entered text, but it does give you a little advantage in that you can have multiple output options, and the advantage of having just one way to enter your URL requests. It also means that for terms with multiple meanings (e.g. “Alfred”), you can default the dearch ressult to something specific.

The use of custom link data is entirely optional, but if you have frequently used links, this will inevitably be faster as when the Slink workflow runs, Alfred will check a local file of data, which is quicker than having SearchLink retrieve data from the Internet, which is the fallback position after the custom data has been checked for.

The data file defaults to being stored in searchlinkcustom.json in your home directory. If it does not exist, triggering the editing flow with the slcustom keyword will also create the file.

The file should be populated with JSON data based on the following structure:

{
	"search term in lower case text" :
	{
		"name" : "The name to include in a Markdown link",
		"url" : "The URL to be used"
	}
}

An example file might look something like this:

{
	"alfred" : 
	{
		"name" : "Alfred",
		"url" : "https://alfredapp.com"
	},
	"doctor drafts" : 
	{
		"name" : "Doctor Drafts",
		"url" : "https://doctordrafts.thoughtasylum.com"
	},
	"my alfred wf" : 
	{
		"name" : "ThoughtAsylum Alfred Workflows",
		"url" : "https://www.thoughtasylum.com/alfred/#downloadable-alfred-workflows"
	}
}

If I then use alfred, doctor drafts, or my alfred wf as my input (in any text case) to a search called by Slink, then the data returned will be from this file rather than the data being retrieved from online by SearchLink.

Change Log

  • Version 1.2.0: 2023-05-14
    • Add: Option to select from list of available features - associated with slink keyword.
    • Add: New hotkey triggers.
    • Add: New snippet triggers.
    • Add: New external triggers.
    • Add: New universal action triggers.
    • Add: Option to utilise a new set of custom override data (end user created).
    • Change: Lots of restructuring of workflow.
    • Change: Changed Path to text editor configuration to use file picker.
    • Change: Updated wording and labelling in workflow configuration page.
    • Change: Updated wording in about this workflow.
    • Change: Modified insertion to use inbuilt Alfred mechanism.
    • Change: Updated icon to be clearer in both dark and light Alfred themes.
    • Fix: Mislabeled meta key adjustment on ‘Search Link Copy’ flow.
  • Version 1.1.0: 2022-11-20
    • Add: Functionality to allow automated insertion of copied result.
    • Add: Added keyword triggers for copy and insert.
    • Add: Snippet trigger (slink;) for default SearchLink action (sl).
    • Add: Several new external triggers for searching and triggering keyword flows, as well as editing the SearchLink configuration file.
    • Change: Default sl behaviour (copy/copy & insert) now determined by a new option.
    • Change: slc no longer opens the configuration file. This is now configured by sle, the prior keyword now being explicitly used for copy.
    • Change: Changed path for configuration file editor from an environment variable to user configuration.
  • Version 1.0.1: 2022-03-06
    • Fix: Fixed subtitle wording on sl invocation.
  • Version 1.0.0: 2021-05-21
    • Add: Initial release, everything is new.

Slink is just one of several Alfred workflows I have created. You can find more workflows and blog posts related to Alfred on my Alfred page.