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.
Reads a stream’s actual volume index, permitted range, mute and fixed-volume state. Returns nil when the read is unavailable.
Documented for app version 1.0.64Updated:
System is a global table: call its functions with a dot (System.<method>(...)), not a colon. Requires Macro Handler 1.0.62 or later.
In system flow, design steps as observe first and act second when the API can affect device state.
stream: music, ring, notification, alarm, system. Result fields: stream, index, min, max, percent, fixed, muted. Percent is calculated from the actual index; it is undefined and nil when min==max. Invalid input or a failed read returns nil for the whole table.
Root is not required; Android audio policies apply. Fixed-volume devices, Do Not Disturb access and OS restrictions may reject an operation. The API does not request or elevate permission. Use it on the macro runtime thread; it does not perform work on the main UI thread.
This read-only call neither plays audio nor changes volume. Do not interpret nil as a zero volume level.
The snippet below is a starter pattern that can be applied directly in runtime flow.
local state = System.getVolume("music")
if state ~= nil then
print(state.index, state.min, state.max, state.percent, state.fixed, state.muted)
endFrom 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.
local state = System.getVolume("music")
if state ~= nil then
print(state.index, state.min, state.max, state.percent, state.fixed, state.muted)
endlocal stepOk = true
local state = System.getVolume("music")
if state ~= nil then
print(state.index, state.min, state.max, state.percent, state.fixed, state.muted)
end
if stepOk then
wait(200)
endlocal ok, err = pcall(function()
local state = System.getVolume("music")
if state ~= nil then
print(state.index, state.min, state.max, state.percent, state.fixed, state.muted)
end
end)
if not ok then
print("API step failed: System.getVolume: " .. tostring(err))
requestStop()
end-- In system flow, design steps as observe first and act second when the API can affect device state.
local function run_getvolume_step()
local state = System.getVolume("music")
if state ~= nil then
print(state.index, state.min, state.max, state.percent, state.fixed, state.muted)
end
end
local ok, err = pcall(run_getvolume_step)
if not ok then
toast("Step failed")
print(err)
endlocal state = System.getVolume("alarm")
if state == nil then
print("Volume unavailable")
else
print(state.index, state.percent)
end