Object MethodTouch and Actions

Trigger.pause(observer, paused?)

Pauses one observer; false resumes it. Events queued before resume cannot start actions. Pausing the macro also pauses every action.

Documented for app version 1.0.59Updated:

Detailed Explanation

This section explains when to use the API, how to call it, and which structures it works best with in production flow.

How To Call It

Trigger is a global table: call its functions with a dot (Trigger.<method>(...)), not a colon. Requires Macro Handler 1.0.60 or later.

When To Use It

In automation flow, chain actions with short wait() intervals and use requestStop() or controlled retry on failure paths.

Parameters and Return

Required: observer. Optional: paused (omit to pass nil and use the runtime default). Returns a boolean (true or false).

Options and Limits

events contains at least one event. packageName filters apps/notifications and textContains filters notification text. timeoutMs: 0–86400000 (default 60000; 0 until stopped), intervalMs: 50–60000 (250), cooldownMs: 0–86400000 (1000), maxEventAgeMs: 100–86400000 (30000), maxEvents: 0–1000000 (1; 0 unlimited). Combine constraints key/operator/value entries with constraintMode="all", "any" or "none". Unknown state cannot pass even a not-equal constraint. condition requires a check function and fires on false-to-true transitions; fireInitially=true also accepts the first true state. Event names: app_foreground, app_background, network_connected, network_disconnected, network_changed, internet_available, internet_lost, vpn_connected, vpn_disconnected, proxy_changed, screen_on, screen_off, device_unlocked, charger_connected, charger_disconnected, battery_changed, power_save_changed, headset_changed, orientation_changed, notification_posted, notification_removed, interval, condition, wifi_connected, wifi_disconnected, cellular_connected, cellular_disconnected, metered_changed, battery_low, battery_okay, time_changed, timezone_changed, charging_started, charging_stopped, headset_connected, headset_disconnected. State keys: connected, validated, vpn, proxy, screenOn, unlocked, charging, powerSave, battery, foregroundPackage, orientation, wifi, cellular, ethernet, metered, roaming, wiredHeadset, batteryTemperature, localTime, weekday, inputIdle. Operators are eq/ne, plus gt/lt/ge/le for numeric fields. Boolean values are true/false, orientation is portrait/landscape, battery is 0–100. Notification text filter is at most 512 UTF-16 units and is case-insensitive. constraintGroups supports up to four nested ALL/ANY/NONE levels and 64 total groups and conditions. source="event" reads event fields; default source="state" reads device state. String operators match literal case-sensitive text. Numbers accept gt/lt/ge/le/eq/ne; localTime uses inside/outside with HH:mm-HH:mm, including overnight windows. weekday is Monday=1 through Sunday=7; batteryTemperature is Celsius. priority is 0–100, higher first. Trigger.watch defaults omitted timeoutMs and maxEvents to zero. Actions wait until held input is released.

Best Combined With

Observation lasts only while the macro runs; this is not a persistent background scheduler. At most 8 subscriptions and 128 events per subscription are allowed; overflow raises an error. Stop and run completion release listeners. App events require connected accessibility; notification events require connected notification access. VPN describes the default network visible to MacroHandler and proxy describes Android HTTP/PAC configuration; neither proves tunnel health or the traffic of other apps. For long-running coded observers put -- @mh:user-infinite-loop at the start of the script; visual blocks add it automatically. Without it the experimental native engine retains a 10-minute hard deadline. The directive preserves stop, heap and continuous active-code protections.

Example Usage

The snippet below is a starter pattern that can be applied directly in runtime flow.

local h = Trigger.watch({events={"interval"}}, {action=function() print("tick") end})
Trigger.pause(h)
wait(500)
Trigger.pause(h, false)
wait(500)
Trigger.close(h)

Copyable Progressive Examples

From foundation to combined usage, each level is provided as a separate code block so you can copy the level you need and adapt it directly.

Foundation

Shows the shortest direct way to call the API.

Foundation
local h = Trigger.watch({events={"interval"}}, {action=function() print("tick") end})
Trigger.pause(h)
wait(500)
Trigger.pause(h, false)
wait(500)
Trigger.close(h)

Simple

Wraps the base call with minimal flow control.

Simple
local stepOk = true
local h = Trigger.watch({events={"interval"}}, {action=function() print("tick") end})
Trigger.pause(h)
wait(500)
Trigger.pause(h, false)
wait(500)
Trigger.close(h)
if stepOk then
  wait(200)
end

Practical Flow

A practical pattern for real macros with pcall, logging, and guards.

Practical Flow
local ok, err = pcall(function()
  local h = Trigger.watch({events={"interval"}}, {action=function() print("tick") end})
  Trigger.pause(h)
  wait(500)
  Trigger.pause(h, false)
  wait(500)
  Trigger.close(h)
end)

if not ok then
  print("API step failed: Trigger.pause: " .. tostring(err))
  requestStop()
end

Detailed

This level packages the API into a reusable helper with error reporting.

Detailed
-- In automation flow, chain actions with short wait() intervals and use requestStop() or controlled retry on failure paths.
local function run_pause_step()
  local h = Trigger.watch({events={"interval"}}, {action=function() print("tick") end})
  Trigger.pause(h)
  wait(500)
  Trigger.pause(h, false)
  wait(500)
  Trigger.close(h)
end

local ok, err = pcall(run_pause_step)
if not ok then
  toast("Step failed")
  print(err)
end

Combined

Combines the API with related structures to form a more realistic workflow.

Combined
local h = Trigger.watch({events={"interval"}}, {action=function() print("tick") end})
Trigger.pause(h)
wait(500)
Trigger.pause(h, false)
wait(500)
Trigger.close(h)