Skip to content

plist

Apple property list codec. Output is XML plist — the human-readable form used by defaults write and most files under ~/Library/Preferences/. Decoding accepts both XML and binary plists.

See the formats overview for the shared codec shape and encoding rules common to every format.

Examples

Materialize a Library plist:

lua
local rb = require("rootbeer")

rb.plist.write("~/Library/Preferences/com.example.MyApp.plist", {
  Theme = "Dark",
  RecentDocuments = { "a.md", "b.md" },
  WindowFrame = { x = 100, y = 100, w = 800, h = 600 },
})

Patch a single key in an existing plist:

lua
local cfg = rb.plist.read("~/Library/Preferences/com.example.MyApp.plist")
cfg.Theme = "Light"
rb.plist.write("~/Library/Preferences/com.example.MyApp.plist", cfg)

Notes

  • Plist Date and Data values decode to strings on read; encoding back produces a string, not the original typed value.
  • Round-tripping a binary plist always re-encodes as XML.

API

rootbeer.plist.decode(s)

Parses a plist string (XML or binary) into a Lua table.

Parameters

sstring
The plist contents.

Returns

table — The decoded value.

rootbeer.plist.encode(t)

Serializes a Lua table to an XML plist string.

Parameters

ttable
The table to serialize.

Returns

string — The XML plist (no trailing newline).

rootbeer.plist.read(path)

Reads and decodes a plist file. Equivalent to decode(slurp(path)). Both XML and binary plists are accepted. Path supports ~ expansion and is resolved against the script directory. This call is synchronous — the file must exist at plan time.

Parameters

pathstring
The file to read.

Returns

table — The decoded value.

rootbeer.plist.write(path, t)

Encodes a table and writes it to a file as an XML plist. Equivalent to rb.file(path, encode(t)). The write is deferred until the apply stage. A trailing newline is always added so the file is well-formed.

Parameters

pathstring
The destination file path.
ttable
The table to serialize.