How To Call It
KV is a singleton global table: call its functions with a dot (KV.<method>(...)).
Persistent key-value storage private to the macro. Each macro has its own store; a value is limited to 1 MB and the store to 10 MB.
Documented for app version 1.0.51Updated:
KV is a singleton global table: call its functions with a dot (KV.<method>(...)).
In data flow, chaining JSON, Regex, Str, Map, and File steps to normalize intermediate values reduces error risk.
KV offers 14 methods; each method page lists its parameters and return value.
Limits: 1 MB per value and 10 MB for the whole store (KV.set, KV.append and KV.setAll raise an error past the limit). The store is separated by macro id, so another macro’s KV data cannot be read. Keys must be strings.
When combined with Str, JSON, Regex, Array, Map, and File, data transformation becomes much more readable in script flow.
The snippet below is a starter pattern that can be applied directly in runtime flow.
local runs = KV.increment("runs", 1)
KV.set("last_run", DateTime.now():format("yyyy-MM-dd HH:mm"))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.
local runs = KV.increment("runs", 1)
KV.set("last_run", DateTime.now():format("yyyy-MM-dd HH:mm"))local runs = KV.increment("runs", 1)
KV.set("last_run", DateTime.now():format("yyyy-MM-dd HH:mm"))
-- Continue with one focused method on the object.local runs = KV.increment("runs", 1)
KV.set("last_run", DateTime.now():format("yyyy-MM-dd HH:mm"))
local note = "KV overview loaded"
print(note)-- In data flow, chaining JSON, Regex, Str, Map, and File steps to normalize intermediate values reduces error risk.
local function run_kv_step()
local runs = KV.increment("runs", 1)
KV.set("last_run", DateTime.now():format("yyyy-MM-dd HH:mm"))
end
local ok, err = pcall(run_kv_step)
if not ok then
toast("Step failed")
print(err)
endlocal runs = KV.increment("runs", 1)
KV.set("last_run", DateTime.now():format("yyyy-MM-dd HH:mm"))
local raw = File.read("macro.log")
local normalized = Str.trim(raw)
print(normalized)