Alloy allows using macros to compose textual values, such as action's name, URLs, etc. Macros can be embedded in free-form text and each macro can be defined as $(<expression>). In the simplest case, expression is a variable's name. For example, text "Call $(contactName)" would be expanded to "Call Kate".

Complete definition of macro is:

$(<variable>[| variable1 | variable2…][%format][=default])

To define a simple macro for variable:

$(contactName)

To define default value should be used when variable has no value - use = operator:

$(lastName = "Noname") - either last name or "Noname" if last name is not defined.

If default value is not surrounded by quotes - it is interpreted as a variable:

$(lastName = fistName) - either last name or first name if last name is not defined.

To define several variables to choice use | operator. The first variable in the list that has value will define the result for macro:

$(lastName | firstName) - either last name or first name if last name is not defined.

$(lastName | firstName = "Noname") - last name or first name or "Noname" if both names are not defined.

By default, macro uses textual representation of variables as implemented in the variable's Type. Though, it is possible to define format for Date and numeric variables using the % operator - $(variable%format).

Date format is defined as dateFormat<,timeFormat><@timeZone> where dateFormat and timeFormat is one of the following format specifiers:

Specifier

Description

Sample

n

none, formats date or time as empty string


s

short, formats date or time in short style

11/23/14, 3:50 PM

m

medium, formats date or time in medium style

Nov 24, 2015, 3:50:24 PM

l

long, formats date or time in medium style

November 24, 2015, 3:50:24 PM PST

f

full, formats date or time in full style

Tuesday November 23, 2014 AD, 3:50:24 PM Pacific Standard Time

%format

custom format

%yyyy-MM-dd 'at' HH:mm

For example:

$(date%n,s) - 3:50 PM 

$(date%s,s) - 1/23/14, 3:50 PM

$(date%%yyyy-MM-dd 'at' HH:mm) - 2014-01-23 at 15:50

Time zone can be either a variable holding time zone or a string representing offset in seconds from GMT. For example:

$(date%n,s@location.timeZone) - 1:50 PM for GMT-2

$(date%n,s@-7200) - 1:50 PM for GMT-2

Number format is defined in printf specification. For example:

$(bill%.02f) - 123.25

$(bill%d) - 123


See also:
Variables
Tasks and Workflows
Actions

Next > Action Environment