script_filter_object¶
- class afwf.script_filter_object.ScriptFilterObject[source]¶
Base class for all objects that appear in an Alfred Script Filter JSON payload (e.g.
Item,Icon,Text,ScriptFilter).Ref: https://www.alfredapp.com/help/workflows/inputs/script-filter/json/
—
Alfred’s JSON protocol differs from standard Python OOP serialization in several ways.
to_script_filter()implements these rules explicitly:``None`` → field must be absent (not
null). Alfred interprets a missing key as “use default”, not as a null value. Standard serialisation would emit"subtitle": null; Alfred expects the key to simply not appear.``False`` / ``0`` / ``””`` → must be preserved. These are falsy in Python but carry real meaning in Alfred’s protocol. Most importantly: if
validis absent Alfred defaults totrue, sovalid=Falsemust appear in the output. Standard OOP serialisers handle this correctly; a naïveif v:falsy-filter does not (bug).Empty nested ``ScriptFilterObject`` → field must be absent. A
Text()with no fields set serialises to{}. Sending"text": {}to Alfred is noise and may confuse some versions of Alfred. These are omitted by callingto_script_filter()recursively and skipping the result when it is an empty dict.Top-level ``dict`` field that is ``{}`` → omit. e.g.
variables: dict = {}on anItemmeans “no variables”, which is identical to the key being absent. Alfred ignores both.``variables: {}`` *inside* ``mods`` → must be preserved. Alfred distinguishes between a mod without a
variableskey (inherits the item’s variables) and a mod with"variables": {}(explicitly clears inheritance). Therefore this rule applies only to the top-level fields of aScriptFilterObject, and plaindictvalues are passed through as-is without recursive stripping.``list`` fields → always preserved, even when empty.
ScriptFilteris required to return anitemsarray (even[]), so list fields are never omitted regardless of their content.
- model_config: ClassVar[ConfigDict] = {'arbitrary_types_allowed': True}¶
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].