Object MethodTouch and Actions

Automation.action(command, args?)

Executes a catalogued Android action under the same validation and permission rules; returns true on success and raises an error on failure.

Documented for app version 1.0.64Updated:

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

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

When To Use It

Executes a catalogued Android action under the same validation and permission rules; returns true on success and raises an error on failure.

Parameters and Return

command is the catalogue identifier; args is a table of command-specific fields. Values may be strings, finite numbers or booleans. Unknown commands or fields, missing required values and out-of-range numbers are rejected. Root and Android permissions are still required.

Best Combined With

Android Actions mode in the System block uses the same catalogue. No separate action plan is required. Use pcall for deliberate error handling and Automation.check for conditional execution. In 1.0.62, media_control {command="pause"} dispatches an Android media-key pair and set_volume {stream="music", percent=30} verifies the nearest volume step. Media dispatch does not confirm playback; Android audio policies still apply. screen_timeout {duration=30, unit="s"} verifies the saved screen timeout. Units are ms/s/min, default 30 s; at most six decimal places must convert to whole milliseconds (15000–2147483647), without rounding. WRITE_SETTINGS is required; no permission screen opens and physical display turn-off is not guaranteed.

Example Usage

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

local message = "Ready"
Automation.action("toast", {text = message})

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 message = "Ready"
Automation.action("toast", {text = message})

Simple

Wraps the base call with minimal flow control.

Simple
local stepOk = true
local message = "Ready"
Automation.action("toast", {text = message})
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 message = "Ready"
  Automation.action("toast", {text = message})
end)

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

Detailed

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

Detailed
-- Automation.action(command, args?)
local function run_action_step()
  local message = "Ready"
  Automation.action("toast", {text = message})
end

local ok, err = pcall(run_action_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 message = "Ready"
Automation.action("toast", {text = message})