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.

Important

If you need access to a UI {value:id.property} within a JSON Action Command, these values must be placed into variables.

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"
}
pulse
OBJECT

Update the configuration for the pulse.

JSON Action Commands

The following JSON Action commands are available as properties of the JSON Action, and processed in the specified order:

remove
JSON ACTION
View properties

Remove components from the UI by id.

insert
JSON ACTION
View properties

Insert new components into the UI.

update
JSON ACTION
View properties

Update components in the UI by id.

replace
JSON ACTION
View properties

Replace components in the UI by id.

sheet
JSON ACTION
View properties

Show a modal sheet overlay on your UI.

share
JSON ACTION
View properties

Show the macOS Share sheet.

sound
JSON ACTION
View properties

Play a sound.

speak
JSON ACTION
View properties

Speak some text.

copy
JSON ACTION
View properties

Copy data to the macOS clipboard.

open
JSON ACTION
View properties

Open file(s) or url(s) in macOS.

opendialog
JSON ACTION
View properties

Show a macOS Open dialog to select a file.

window
JSON ACTION
View properties

Basic controls over the window where available.

notification
JSON ACTION
View properties

Post notifications to macOS Notification Centre.

functions
JSON ACTION
View properties

Run function(s) on relevant components by id.

popupmenu
JSON ACTION
View properties

Show a popup menu for the given component identifier.

finish
JSON ACTION
View properties

Finish this instance of an Alfred UI, either closing it, or returning context back to Alfred.