Using Variables in Workflows

When creating a workflow you may find yourself needing to save values, such as the output of actions, to use later on. This is where you might resort to variables: a way to temporarily store text you can reference by name.

Variables are available in most fields throughout most workflow objects. Define static variables in the Workflow's Configuration, or set them dynamically within a workflow run with the Arg and Vars Utility or the JSON Utility.

The Example Workflows in the Arg and Vars Utility references several workflows using variables. In this guide we'll be focusing on Simple To-Do List.

Simple To-Do List canvas

Setting Variables Within a Workflow

In the Simple To-Do List workflow, step 2 (in orange) is an Arg and Vars Utility used to store the argument you typed in the Keyword Input in step 1. It creates a task variable and sets its contents to {query}, which is a placeholder for whatever input the object received.

First Arg and Vars

In step 5, the same method is used to save the argument chosen in the List Filter Input from step 3/4.

Second Arg and Vars

Reading Variables Within a Workflow

Further down the stream, the Conditional Utility in step 6 expands the contents of the task variable with {var:task}. It does a simple check and picks a path depending on if the variable has any content or is empty.

Consditional

Note

In Alfred objects, variable contents are expanded with the format {var:myvariable}, where myvariable is the name you gave your variable. Prepopulated Environment Variables use the format {const:myvariable}.

In code blocks, such as in a Run Script Action or Script Filter Input, variables are set as environment variables and you access them according to the rules of the language.

Step 7 makes use of the variables we have set so far in a Write Text File Output. You should recognise {var:task} from step 2 and {var:filename} from step 5. {var:todos} comes from the Workflow's Configuration.

Write File

These details are reused in the Post Notification Output in step 8.

Post Notification

Workflow Environment Variables

You can set static variables which are available throughout every object in the workflow in the Environment Variables tab accessible by clicking the [x] on the top right of the workflow canvas.

Important

Give preference to the Configuration Builder for any value that is going to be user-configurable.

Workflow Environment Variables