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:
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:
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
DateandDatavalues 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
sstringReturns
table — The decoded value.rootbeer.plist.encode(t)
Serializes a Lua table to an XML plist string.
Parameters
ttableReturns
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
pathstringReturns
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
pathstringttable