Storage

Persistent key-value store scoped per-macro, survives app restarts

The storage object lets a macro silently save and load data to disk without any UI. Data persists across runs and app restarts. Each macro has its own isolated store — two macros using the same key will not interfere with each other.

Values must be JSON-serializable (strings, numbers, booleans, arrays, plain objects). Non-serializable values (functions, circular references) will throw on set.

storage.set(key, value)

Persists a value to disk under the given key. The value is serialized with JSON.stringify internally.

ParameterTypeDescription
keystringStorage key, unique within this macro.
valueanyAny JSON-serializable value.

Returns booleantrue if saved, false if the quota was exceeded

storage.set("counter", 0);
storage.set("config", { speed: "fast", retries: 3 });
storage.set("history", [1, 2, 3]);

// Check quota
var ok = storage.set("bigData", someHugeObject);
if (!ok) print("Storage full!");

storage.get(key, defaultValue?)

Reads a persisted value. The stored JSON string is deserialized with JSON.parse automatically.

ParameterTypeDescription
keystringStorage key to look up.
defaultValueanyReturned if the key doesn't exist. Defaults to undefined.

Returns T — the stored value, or defaultValue if the key doesn't exist

var count = storage.get("counter", 0);
count++;
storage.set("counter", count);
print("Run #" + count);

var config = storage.get("config", { speed: "normal", retries: 1 });
print(config.speed);

storage.delete(key)

Removes a single key from the macro's storage.

ParameterTypeDescription
keystringStorage key to remove.

Returns void

storage.delete("counter"); // next get("counter") returns defaultValue

storage.clear()

Removes all keys from the macro's storage. Does not affect prompt caches or global variables.

Returns void

// Reset all stored data for this macro
storage.clear();

Quotas

To prevent runaway scripts from filling up device storage, limits are enforced per macro:

LimitValueDescription
Per key64 KBMaximum size of a single serialized value.
Per macro512 KBTotal size of all serialized values combined.

When a set call would exceed either limit, it returns false and the value is not written. Existing data is not affected.

Storage vs Variables: setGlobalVar / getGlobalVar are in-memory only and lost on app restart. storage writes to disk and survives restarts. Use variables for cross-thread communication during a run, and storage for data that must persist.