Object MethodSystem Control

System.setScreenTimeout(durationMs)

Changes the saved screen timeout in whole milliseconds; returns true only after reading back exactly the requested value.

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

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

When To Use It

In system flow, design steps as observe first and act second when the API can affect device state.

Parameters and Return

durationMs: finite integral Lua number from 15000–2147483647. Numeric strings, fractional milliseconds, extra arguments and out-of-range values return false without side effects. No root is required; Android Modify system settings (WRITE_SETTINGS) access is required. Missing access returns false without opening a permission screen or elevating access.

Options and Limits

This is Android’s saved screen-timeout setting, not a guarantee that the physical display will turn off after that interval. Device administration, wake locks and app policies may affect behavior. Settings reads/writes do not run on the main UI thread; stopped operations return false/nil.

Best Combined With

No-Code/Logic: System → Android Actions → Screen timeout. Automation.action("screen_timeout", {duration=30, unit="s"}) uses the same operation and raises an error on failure. Units are ms/s/min, default 30 s. Input accepts at most six decimal places; conversion must produce whole milliseconds without rounding.

Example Usage

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

local verified = System.setScreenTimeout(60000)
print("Saved timeout verified", verified)

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 verified = System.setScreenTimeout(60000)
print("Saved timeout verified", verified)

Simple

Wraps the base call with minimal flow control.

Simple
local stepOk = true
local verified = System.setScreenTimeout(60000)
print("Saved timeout verified", verified)
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 verified = System.setScreenTimeout(60000)
  print("Saved timeout verified", verified)
end)

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

Detailed

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

Detailed
-- In system flow, design steps as observe first and act second when the API can affect device state.
local function run_setscreentimeout_step()
  local verified = System.setScreenTimeout(60000)
  print("Saved timeout verified", verified)
end

local ok, err = pcall(run_setscreentimeout_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 saved = System.getScreenTimeout()
if saved == nil then error("Screen timeout unavailable") end
assert(System.setScreenTimeout(60000), "Screen timeout write was not verified")
print(System.getScreenTimeout())