Skip to content

Saving data

Where an extension keeps settings and other local state with AP.storage and AP.paths.data(), what goes inside the app's project file instead, and what never to store.

Data Where
Settings, preferences, recent items, small caches AP.storage (below)
Bigger files you create or download (images, media, generated presets) A file in AP.paths.data()
Data that belongs to one After Effects or Premiere Pro project Inside the .aep / .prproj, from jsx/ (it travels with the project file)
Secrets (passwords, API keys, tokens) Nowhere. Everything above is a plain file the user can open.

Do not use localStorage, sessionStorage or IndexedDB: in CEP each panel gets its own copy (so panels do not share it), and it lives in a cache folder that can be cleared. Never write into the extension folder (AP.paths.extension()): every update replaces it.

Small JSON values, kept on this computer across launches and updates, shared by every panel of this extension.

var settings = AP.storage.get("settings", { fps: 24, autoApply: false }); // fallback until saved
settings.fps = 30;
AP.storage.set("settings", settings); // true when saved
AP.storage.remove("settings"); // or AP.storage.set("settings", undefined)
AP.storage.keys(); // ["recent", "settings"]
Call Does
get(key, fallback) The saved value, or fallback when nothing is saved (or the file is unreadable).
set(key, value) Saves any JSON value (objects, arrays, strings, numbers, booleans, null). Returns true, or false if the disk write failed.
remove(key) Deletes the value.
keys() Saved keys, sorted.
onChange(key, fn) fn(value) runs when another open panel of this extension sets or removes key (value is undefined after a remove). Returns a function that stops listening.
  • Keys use letters, digits, _, . and - (up to 100 characters, not starting with . or -). An invalid key throws.
  • A value is limited to 1 MB; functions, cyclic objects and other values JSON cannot hold throw. Store bigger data as a file in AP.paths.data().
  • Each key is its own file, written atomically, so a crash never leaves a half-saved value and two panels saving different keys never overwrite each other. If two panels save the same key, the last one wins.
  • get returns a fresh copy from disk: change it, then set it again.

Keep a panel in sync when the settings modal saves:

src/panels/main/main.js
AP.storage.onChange("settings", function (settings) {
applySettings(settings || DEFAULTS);
});

AP.paths.data() returns a folder that exists, belongs to this extension, and survives updates (.../AfterPresets/extensions/<bundleId>/app/). Use Node’s fs and path there for anything that is not a small JSON value:

var fs = require("fs");
var path = require("path");
var file = path.join(AP.paths.data(), "thumbnails", "intro.png");

Pass such paths to ExtendScript as arguments when the app needs them (see assets.md).

Data about one project (which presets it uses, a layout you applied) belongs in the project, not on the computer: it should follow the .aep or .prproj to another machine. Read and write it from a jsx/ function, for example in a project XMP field or on a layer or comp comment, and call it with ctx.host.eval.