Skip to content

Predicate Search

Brandon Dalton edited this page Dec 1, 2026 · 4 revisions
  • Filtering on event type and process path only goes so far. Eventually the question we want answered is about one field of the record. For example, "which osascript execs asked for a password?". Predicate search lets you ask that question directly.
  • A predicate is an NSPredicate evaluated on each event's record. That's the same JSON Export Telemetry writes, so every key in the telemetry schema can be used.

Where to write one

  • Predicate Editor (View > Predicate Editor, ⌥⌘F): sits beside the event tables or pops out into its own window. It colors syntax, completes key paths as you type, and flags keys the schema doesn't name. Apply (⌘↩) filters the tables. Predicates you save are kept under Saved, and the ones you apply under Recent.
  • Search field (⌘F): filters by each event's context as you type. With a predicate applied, it narrows that predicate's matches.
  • Command line: sudo macmonitor stream --predicate '...' uses the same engine. Repeating --predicate ANDs them together.
  • Telemetry Schema window: lists every key a record has.

Examples

es_event_type == "ES_EVENT_TYPE_NOTIFY_EXEC" AND event.exec.target.executable.name == "osascript"

(event.exec.script_content CONTAINS[c] "display dialog" AND event.exec.script_content CONTAINS[c] "password")
    OR (event.exec.command_line CONTAINS[c] "display dialog" AND event.exec.command_line CONTAINS[c] "password")

es_event_type == "ES_EVENT_TYPE_NOTIFY_DELETEEXTATTR" AND event.deleteextattr.extattr ENDSWITH "apple.quarantine"

event.exec.target.is_adhoc_signed AND event.exec.target.euid == 0
  • A boolean key path can stand on its own, as is_adhoc_signed does above. It reads as == YES.
  • event.exec != nil names an event's type by its payload, as es_event_type == "ES_EVENT_TYPE_NOTIFY_EXEC" does. A network flow's record has no es_event_type, so event.new_flow != nil and event.flow_closed != nil name its type.

Related events (search only)

In Mac Monitor's window, a SUBQUERY can compare an event with other events in the trace. Inside it, $e. is the related event and a plain key path is the event being searched:

SUBQUERY(process_group, $e, $e.es_event_type == "ES_EVENT_TYPE_NOTIFY_CREATE").@count > 0
  • This matches an event whose process group created a file.
  • Relations: events, process_group, session_group, correlated (the process an EXEC or FORK created), and process_events.
  • macmonitor stream and indicators look at one event at a time, so neither takes a SUBQUERY.

A longer example: an adhoc signed process maps an Open Scripting Architecture component, then connects to mDNSResponder's socket. That connection is a DNS lookup, which usually comes right before a network connection.

target_path ENDSWITH "/mDNSResponder" AND process.is_adhoc_signed
    AND SUBQUERY(process_events, $e, $e.target_path CONTAINS "Script.component" AND $e.mach_time < mach_time).@count > 0
  • It matches the UIPC_CONNECT, one event per lookup. Script.component covers both AppleScript.component and JavaScript.component. process_events goes through the other events of the same process, and $e.mach_time < mach_time keeps only the mappings that came before the connection.

Limits

  • macmonitor runs as root, so predicates are data-only. FUNCTION, CAST, and any key the schema doesn't name are refused when the predicate is parsed. NSPredicate's own arithmetic, string, and aggregate functions are allowed.
  • MATCHES gives up on a value after 0.5 seconds, so a regular expression that backtracks without end can't stall a stream or a search.
  • An indicator's predicate runs in the Security Extension, which takes less. See Indicators.

Clone this wiki locally