Variables
Variables enable setting data and values for linking back-end logic to your user interfaces, and make use of placeholders throughout the JSON.
"text": "{var:variablename}"
ImportantSome placeholders are preprocessed, and some are dynamically processed at the point of use.
The placeholders page explains how and when variables will be resolved.
Variables Configuration
On setting up a UI, variables can be optionally configured in the ui.json to have additional behaviour using the variablesconfig property.
"variablesconfig": {
"dinner": {
"default": "bread",
"persist": false,
"scriptenv": true,
"src": "args[3]"
}
}
ImportantBy default Alfred UI does not load the variables set in the rest of the workflow. You must specify which you want to make available at launch time by configuring them in
variablesconfigwith the same name and"src": "variable".
Each variable is keyed by name with the following properties:
- default
- STRING
- Default:
null
The default value for this variable, used when a variable value is set to null.
Also used to coordinate what is saved when persisting variables.
- persist
- BOOL
- Default:
false
The value of this variable will be persisted when it is different to the default value, and automatically re-set at UI start up.
- scriptenv
- BOOL
- Default:
false
This variable will be passed to the script environment e.g. running actions or the pulse
- src
- SPECIAL
- Optional
Set the initial value of this variable to a launch arg or variable.
| Value | Description |
|---|---|
| args[x] | Set the initial value to a specific passed-in argument. |
| args | Set the initial value to all of the passed-in arguments as an array. |
| variable | Set the initial value to a context based variable (i.e. workflow variable). |
Initial Variables
Set the initial value of a variable for when the UI starts up using the variables property of the ui.json.
"variables": {
"dinner": "cheese"
}
This differs from the default property of the Variables Configuration as it is setting the variable value to be used, and not the default value when the variable isn't set.
Setting Variables
Variables can be set at runtime during Actions with the variables property, and via JSON Actions with the variables property.