macotron.plist
Read a property list file, or parse plist text or bytes, into plain JavaScript objects. Binary, XML, and OpenStep plists all work, with no plutil or defaults in between.
// The version of an installed app, straight from its Info.plist.
const info = macotron.plist.read("/Applications/Safari.app/Contents/Info.plist");
console.log(info?.CFBundleShortVersionString);
Values
Dictionaries become objects, arrays become arrays, and strings, numbers, and booleans stay as they are. A date becomes a number of milliseconds since 1970, so new Date(value) turns it back into a date. Data becomes a base64 string.
Some apps store a whole plist as a Data value inside another plist. Pass that base64 string to parse({ base64 }) to read the inner one.
Reading
read(path: string): any | null
The parsed contents of the file. A leading ~ expands to your home folder. Returns null when the file is missing, cannot be read, or is not a plist. The call is synchronous.
parse(text: string): any | null
Parses an XML or OpenStep plist given as text. Returns null when the text is not a plist.
parse({ base64: string }): any | null
Parses plist bytes given as base64, in any format, binary included.
// Screen Sharing keeps its saved computers as a binary plist inside its prefs.
const prefs = macotron.plist.read(
"~/Library/Containers/com.apple.ScreenSharing/Data/Library/Preferences/com.apple.ScreenSharing.plist");
const store = prefs && macotron.plist.parse({ base64: prefs.connectionsStore });
console.log(Object.keys(store?.connectionDetails || {}).length, "saved computers");
See also
- macotron.prefs to read and write preference domains, as
defaultsdoes. - macotron.app
info()for an app's name and version. - The
screen-sharing.js,emoji.js, andsecurity-checklist.jsplugins.