Alfred 5.5 is here - Find out what's new

Using Variables in Workflows

When creating a workflow, you may find yourself needing to enter or select multiple arguments to use later on. This is where you might resort to variables: a way to temporarily store text you can reference by name. They can be used in keywords, arguments, JSON utilities, and more.


Getting Started with Workflow Variables

We've included a few workflows in the Getting Started guides and examples in Alfred, which you can find under the [+] button at the bottom of the Workflows sidebar in Alfred's preferences.

In particular, the Getting Started > Workflow Variables and the Examples > Simple To-Do List make use of variables to store multiple pieces of information throughout the workflow.

To-Do List Example Workflow

In Alfred objects, variable contents are expanded with the format {var:myvariable}, where myvariable is the name you give your variable when creating it. In code blocks, such as in a Run Script or Script Filter, they are set as environment variables and you access them according to the rules of the language.

You can set static variables in the Workflow Configuration or Workflow Environment Variables panes. To set them dynamically within a workflow run, use the Arg and Vars or JSON utilities.

Setting Variables Within a Workflow

For more dynamic use of variables, you can set them as you proceed through the objects of your workflow.

Use the in-workflow variables for:

  • Saving the input text query for use later
  • Dynamically overriding a fixed variable

In the Simple To-Do List workflow, the orange object is the first Arg and Vars utility, used to store the query you've just typed.

To-do list variable

Further down, the {var:task} variable is used to filter the action to either take the green path where the variable is not empty and the task is added to a list, or the blue path where the variable is empty and the list is opened instead.

The yellow list filter object also sets an argument (selected from the pre-defined List Filter options) which is saved as {var:filename} to set the to-do list to which the {var:task} will be added.

In the Write File green object on the top stream, three variables are used;

  • The {var:path} adds the file path set in the Workflow Environment Variables
  • The {query} adds the name of the file selected in the yellow List Filter object
  • The {var:task} inserts the content; taken from the very first object where I typed the task I wanted to add.

Variables in use in Append To File object

Setting Workflow Environment Variables

The same Simple To-Do List workflow includes a todos_path variable which sets where the to-do lists are saved. Click the [x] in the top right of your workflow and switch to the Workflow Environment Variable tab to edit it.

Workflow Environment Variables

Workflow Environment Variables are useful to set global values you need to reference throughout the Workflow. If you want others to be able to edit these values locally (e.g. to use a custom path or set an API key for a service), see Workflow Configuration.

Latest Blog Post:

Watch Alfred Videos on YouTube

CacheFly Campaign Monitor

"Alfred" is a registered trademark of Running with Crayons Ltd. ©2024 Running with Crayons Ltd. All rights reserved.

Terms & Conditions, Privacy Policy, Cookies.