JSON Actions
JSON Actions allow for UIs to be manipulated and updated, along with performing functions, playing sound and more.
They can be used instead of scripts as a simple way to e.g. update some variables or context when an event is triggered, or be passed as the return from a script for processing after some scripted back-end logic changes.
Understanding Values and Variables
Variables are a way of dynamically providing data for the JSON Action Commands. Variables can be set within your UI JSON code directly, or returned as a result of a script.
ImportantIf you need access to a UI
{value:id.property}within a JSON Action Command, these values must be placed intovariables.
You must add any UI getter values into variables if you need to access them in a JSON action. This allows predictable access to any UI component with an id before the JSON Actions are processed, which in turn may edit or update the UI itself.
Variables are expanded before passing to the JSON Action Commands.
Example
"action": {
"type": "json",
"variables": {
"chosensound": "{value:soundfield.text}"
},
"src": {
"sound": {
"src": "{var:chosensound}"
}
}
}
Properties
- variables
- OBJECT
A map of variables which can also contain placeholders e.g. {var:varname}, {value:id.property}
{
"food": "{var:somefood}",
"pvalue": "{value:mypicker.selected.value}",
"person": "vero"
}
JSON Action Commands
The following JSON Action commands are available as properties of the JSON Action, and processed in the specified order:
- finish
- JSON ACTION
- View properties
Finish this instance of an Alfred UI, either closing it, or returning context back to Alfred.