The Workflow3 class for Alfred 3

Workflow3 supports Alfred 3’s new features.

It is an Alfred 3-only version of Workflow.

It supports setting Workflow variables and the more advanced modifiers supported by Alfred 3.

In order for the feedback mechanism to work correctly, it’s important to create Item3 and Modifier objects via the Workflow3.add_item() and Item3.add_modifier() methods respectively. If you instantiate Item3 or Modifier objects directly, the current Workflow3 object won’t be aware of them, and they won’t be sent to Alfred when you call send_feedback().

class workflow.workflow3.Workflow3(**kwargs)

Workflow class that generates Alfred 3 feedback.

add_item(title, subtitle=u'', arg=None, autocomplete=None, valid=False, uid=None, icon=None, icontype=None, type=None, largetext=None, copytext=None, quicklookurl=None)

Add an item to be output to Alfred.

See add_item() for the main documentation.

The key difference is that this method does not support the modifier_subtitles argument. Use the add_modifier() method instead on the returned item instead.

Returns:Alfred feedback item.
Return type:Item3
getvar(name, default=None)

Return value of workflow variable for name or default.

Parameters:
  • name (unicode) – Variable name.
  • default (None, optional) – Value to return if variable is unset.
Returns:

unicode or default: Value of variable if set or default.

item_class

alias of Item3

send_feedback()

Print stored items to console/Alfred as JSON.

setvar(name, value)

Set a workflow variable that will be inherited by all new items.

Parameters:
  • name (unicode) – Name of variable.
  • value (unicode) – Value of variable.
class workflow.workflow3.Item3(title, subtitle=u'', arg=None, autocomplete=None, valid=False, uid=None, icon=None, icontype=None, type=None, largetext=None, copytext=None, quicklookurl=None)

Represents a feedback item for Alfred 3.

Generates Alfred-compliant JSON for a single item.

You probably shouldn’t use this class directly, but via Workflow3.add_item(). See add_item() for details of arguments.

add_modifier(key, subtitle=None, arg=None, valid=None)

Add alternative values for a modifier key.

Parameters:
  • key (unicode) – Modifier key, e.g. "cmd" or "alt"
  • subtitle (unicode, optional) – Override item subtitle.
  • arg (unicode, optional) – Input for following action.
  • valid (bool, optional) – Override item validity.
Returns:

Configured Modifier.

Return type:

Modifier

getvar(name, default=None)

Return value of workflow variable for name or default.

Parameters:
  • name (unicode) – Variable name.
  • default (None, optional) – Value to return if variable is unset.
Returns:

unicode or default: Value of variable if set or default.

obj

Return Modifier formatted for JSON serialization.

Returns:Data suitable for Alfred 3 feedback.
Return type:dict
setvar(name, value)

Set a workflow variable for this Item.

Parameters:
  • name (unicode) – Name of variable.
  • value (unicode) – Value of variable.
class workflow.workflow3.Modifier(key, subtitle=None, arg=None, valid=None)

Modify Item3 values for when specified modifier keys are pressed.

Valid modifiers (i.e. values for key) are:

  • cmd
  • alt
  • shift
  • ctrl
  • fn
arg

unicode

Arg to pass to following action.

key

unicode

Modifier key (see above).

subtitle

unicode

Override item subtitle.

valid

bool

Override item validity.

variables

dict

Workflow variables set by this modifier.

getvar(name, default=None)

Return value of workflow variable for name or default.

Parameters:
  • name (unicode) – Variable name.
  • default (None, optional) – Value to return if variable is unset.
Returns:

unicode or default: Value of variable if set or default.

obj

Return modifier formatted for JSON serialization for Alfred 3.

Returns:Modifier for serializing to JSON.
Return type:dict
setvar(name, value)

Set a workflow variable for this Item.

Parameters:
  • name (unicode) – Name of variable.
  • value (unicode) – Value of variable.