Placeholders
Alfred UI JSON supports placehoders for the preprocessing and dynamic processing of properties.
Preprocessing
Before parsing any ui.json or action JSON into native objects and data, the JSON is preprocessed to replace placeholders with their expanded values.
| Placeholder | Description |
|---|---|
"{var:variablename}" |
Replaced with the contents of a variable. Once resolved, the value isn't processed further. |
"{const:constantname}" |
Replaced with the contents of a constant from the Alfred Workflow. |
"{file:filename}" |
Replaced with the contents of a relative file path. Resolves as if the file contents were part of the original JSON and is further processed. |
"{fileraw:filename}" |
Same as "{file:filename}" except contents are not further processed, making it slightly faster for very large files which don’t need preprocessing, such as data for the dataview. |
Ignored Placeholders
Some key properties are not preprocessed as they are either special cases or dynamically processed:
bundleid, variablesconfig, variables, args, action.src, data.filter.
Dynamic Processing
args, variables and action.src are somewhat special keys in that their values get processed at the point of use.
This allows for highly dynamic user interfaces with minimal scripting by being able to obtain placeholders when an action occurs, such as a button being pressed.
Additional placeholders are available for args and variables at the point an action is triggered:
| Placeholder | Description |
|---|---|
"{value:id.property}" |
Replaced with the contents of the property of a UI component. See property getters for more information and examples. |
"{data:property}" |
Replaced with the contents of the property of the data within a dataview cell. |
Type Casting and Compositing
Placeholders are always written as strings, but when replaced become their original value type. This means you can, for example, store an object or array as a variable:
"variables": {
"textreactions": {
"mode": "append",
"scroll": "auto"
}
}
And use it as the value of a complex property:
{
"type": "markdownarea",
"behaviour": "{var:textreactions}"
}
Which is expanded and processed as its original type:
{
"type": "markdownarea",
"behaviour": {
"mode": "append",
"scroll": "auto"
}
}
There is one exception. In addition to being used on their own:
"text": "{var:fruit}"
Placeholders can be composited with strings and other placeholders.
"text": "My favourite type of {var:meal} drink is {var:fruit} juice."
In this case the result is always a string. If one of the placeholders is of a different type, it is converted to a JSON string.