Variables

Base Classes

class base_magic(key: str, ask_each_time: str, attrs: dict)

Base class for magic variables.

__init__(key: str, ask_each_time: str, attrs: dict)
Parameters:
  • key – Key (in the action’s WFWorkflowActionParameters dictionary) to the magic variable’s value
  • ask_each_time – The text used when Ask Each Time is selected as an option.
  • attrs – Dict of information to be passed to HTML.
Ask_each_time:
  • Usually, the text is simply “Ask Each Time”. In inline variables, it is usually “Text”
  • If Ask Each Time is not offered as an valid input, set this value as None
blank() → dict

Handles output when the variable was left blank.

to_html(params: dict, UUID_glyphs: dict) → [<class 'dict'>]

Invoked by the to_django method to convert a variable object to a dict describing the contents of the action.

Parameters:
  • params – The action’s WFWorkflowActionParameters dict. Contains information on what values were filled into each magic variable.
  • UUID_glyphs – Previous actions’ outputs can be used as magic variable inputs, and are displayed alongside the output-action’s glyph. UUID Glyphs maps actions’ output UUIDs to their glyphs.
class line(label: str, leftify: bool = False)

Base class for line variables.

__init__(label: str, leftify: bool = False)
Parameters:
  • label – Label to the left of the parameter, detailing what it is.
  • leftify – Whether or not to flush the variable left against the label. Usually used for line_inline.
to_html() → dict

Simply returns the label wrapped in a dict.

Title Variables

class magic(key: str, blank_text: str, ask_each_time: str)

Basic Magic Variable Field.

In Shortcuts, this simplest of fields can accept:

  • results from other actions
  • “global” variables such as Clipboard, Current Date, Shortcut Input
  • blank (nothing)
blank()

Handles output when the variable was left blank.

class number(key: str, default: str, blank_text: str, ask_each_time: str)

Field that accepts numbers.

In Shortcuts, this accepts:

  • signed floats and integers
  • a single magic variable (no inline expressions)
  • blank (nothing)
NOTE:number may accept a default value. If the default

state is blank, simply self default=None.

blank()

Handles output when the variable was left blank.

class whole_number(key: str, default: str, blank_text: str, ask_each_time: str)

Field that accepts only whole numbers.

In Shortcuts, this is identical to number, except the decimal point is not available.

class counter(key, item: str, ask_each_time, default: int, *_, **__)

Field that counts things.

Plural sensitive, e.g. “1 time” vs “2 times”.

In Shortcuts, this accepts:

  • a natural number (0 or positive ints)
  • can be incremented or decremented
  • Ask Each Time
TODO:implement magic variable support.
TODO:account for the field accepting / not accepting 0 as a valid number.
blank()

Handles output when the variable was left blank.

class choose(key, ask_each_time, default: str, options: [<class 'str'>], *_, **__)

Field that offers a list of valid choices, with a default pre-selected.

In Shortcuts, this field accepts:
  • one of the offered options.
  • a magic variable, and Ask Each Time, may or may not be valid

Some fields simply prompt the user to “Choose a variable…” with no other options.

TODO:account for “Choose a variable…” case.
blank()

Handles output when the variable was left blank.

Line Variables