In Alloy each action executes in its dedicated environment, which provides all the required data. Action environment is composed as a set of nested contexts, where each context holds its own set of variables. To simplify things, there is no need to deal with a particular context - instead each variable should be prefixed to tell runtime where to find and store variable's data.
Context Hierarchy |
Variable Prefix |
Notes |
Runtime Context | one context per action execution | |
Action Context | a: |
one context per each action |
Action Family Context | f: |
one context per action family |
System Context | s: |
one context for entire system |
The following are detailed description of contexts and their variables supported by Alloy.
Runtime Context is a temporary context that exists only during a workflow execution. Variables (runtime), belonging to that context, have no prefix and they will be discarded upon a workflow completion. You can use Runtime variables to hold and transfer data meaningful only during workflow execution. For example, "Web Search" action, that prompts for a search term each time, may store and use search term as a runtime variable (searchTerm).
Built-in Runtime variables are:
$action_in |
stores input for entire action. $action_in may have some value if action is launched with some data via Paste,"Open Saved Data" or "Open in" command in other apps. In other cases $action_in has no value. |
input |
stores input for the current task. input contains output from previous task. For the first task input contains value from $action_in. input may have no value if previous task outputs nothing or $action_in has no value. |
Action Context is a persistent context that is bound to an action it belongs to. Variables (action), belonging to that context, have the a: prefix and they will be persistent as long as the action is present in the app. You can use Action variables to hold data that should be re-used during several action launches. For example, a "Call" action may store a contact (e.g. a:contact) and a phone number (e.g. a:phone) as action variables to prompt the user only once to choose contact and phone number.
Action Family Context is a persistent context that is bound to an action family. Variables (family), belonging to that context, have the f: prefix and they will be persistent indefinitely until the user explicitly decides to delete them. Family variables are shared between several actions belonging to the same family. For example, different "SMS" actions, belonging to the same "sms" family may share the same list of canned SMS's stored as f:smsList.
System Context is a persistent context that is bound to entire system (app). Variables (system), belonging to that context, have the s: prefix and they will be persistent indefinitely. That is why it is very important to think twice before introducing new System variables. You can use System variables to hold data that should be re-used by any actions in the app. For example, various location specific actions may use global list of saved locations (s:locations) accessible for any actions that need it.
Built-in System variables are:
Variable |
Type |
Description |
s:date |
Date |
current date |
s:dateTime |
Date |
current date and time |
s:time |
Date |
current time |
s:location |
Location |
last known location. It is refreshed on each app launch and then in about each 5 min. To get precise location - use a "Get Location" task instead. Note: to use s:location variable - access to Location must be explicitly granted for an action. |
s:clipboard |
Clipboard |
content of system clipboard. This variable is mutable so you can alter it or its properties |
s:uuid |
String |
freshly generated UUID |
s:x-callback |
String |
x-callback-url query |
s:browsers |
Map<String, int> |
maps browser URLs to browser types |
s:photoSources |
Map<String, int> |
maps photo source name to photo source |
s:callTypes |
Map<String, int> |
maps call type name to call type |
s:smsTypes |
Map<String, int> |
maps sms type name to sms type |
s:alerts |
Map<String, int> |
maps alert name to alert value in seconds |
s:searchEngines |
Map<String, String> |
maps search engine name to its URL |
s:cloudServices |
Map<String, int> |
maps Cloud service name to Cloud service |
s:resumeAction | String | query to allow resuming current action |
s:sessionUID | String | UID of current launch session |
See also:
Macro
Variables
Tasks and Workflows
Actions
Next > Variable Types