Page icon

Script Filter Input

The Script Filter Input dynamically populates Alfred results. It is a powerful workflow object allowing you to build and manipulate custom results with your favourite programming language. Run custom scripts for bespoke tasks (such as fetching from an online API) and output the information into a structured JSON format for Alfred to parse.

Demonstration

Setup

Configuration

Configure the Keyword to type in Alfred, and the Placeholder Title and Placeholder Subtext to display by default. The "Please Wait" Subtext shows while waiting for the script's initial results.

Alfred behaves differently depending on the chosen argument handling:

Argument Option Behaviour
Argument Required Holds off on running the script until you begin typing.
Argument Optional Runs the script as soon as the keyword matches.
No Argument Runs the script as soon as the keyword matches. Quits if anything is typed.

Language defines the interpreter to run the code in the Script text area.

with input as argv is always preferred over with input as {query}, as the former doesn't require escaping the input.


Run Behaviour

By default Script Filters rerun your code as additional characters are typed, sending your refined query as a new argument each time. The Run Behaviour configuration provides fine-tuning.

Configuration for Run Behaviour

Queue Mode defines what happens when you continue typing as a script run is underway. Waiting until the previous script finishes allows for results to begin populating sooner, but if your script is too slow it may be worth terminating it every time to wait for the result of the most recently typed argument.

Queue Delay defines how long to wait before running the script after every typed character. This is beneficial if the script is known to be slow to complete or there is an external limits imposed on the script, e.g. from a web API.

Argument defines if surrounding whitespace is relevant to your query or should be ignored.


Alfred Filters Results

With Alfred Filters Results turned on, scripts run once and every additional typed character reduces results from the full initial output. This is highly efficient as it lets you ignore filtering logic in favour of returning every possible match in one go and having Alfred do the heavy lifting of finding matches.

Click the … to access more options.

Configuring Match Mode

Match mode defines how Alfred filters results. Exact options are faster than Word matching. Examples show matches against a My Family Photos string.

Mode Description Long Example Short Example
Exact from start or whitespace Matches if the search query is an exact match from a word boundary in the phrase. Family Photos Photos
Exact from start Matches if the query is an exact match from the beginning of the phrase. My Family My
Word matching - Any order Matches words in the query in any order. Photos Family Ph Fa
Word matching - Sequential Matches words in the query if they appear in the written order. My Photos Fa Ph

Connection Ideas

The Script Filter Input can build powerful connections to a multitude of objects, it all depends on the task it's running.

Example Workflows

Advanced

The Script Filter Input must output a structured JSON format for Alfred to parse.

The Language configuration lists runtimes which have historically been included with macOS. But you're not limited to those entries. If you want to run a script in a different language, either:

  • Save your script with executable permissions and a proper shebang (e.g. #!/usr/bin/env node or #!/usr/bin/env lua) and set External Script as the Language, pointing to your script.
  • Set Language to the default shell /bin/zsh --no-rcs and tell the runtime to call your code from the Script text area (e.g. node MY_SCRIPT.js or lua MY_SCRIPT.lua).

These examples assume the runtimes were installed with Homebrew, as Alfred includes its directories in its PATH.

A number of Alfred-specific environment variables are available to the script.

Keywords aren't limited to a single fixed word. You can extend them to accept multiple values and be configurable by users without them having to modify the workflow's internals.