app.plist - Plist Operations API
Read and write macOS Property List files.
Methods
app.plist.read(path)
Read a plist file.
Parameters:
path(string) - Plist file path
Returns: table|nil - Lua table or nil
local info = app.plist.read("/Applications/Safari.app/Contents/Info.plist")
if info then
app.log.info("Version: " .. info.CFBundleShortVersionString)
app.log.info("Bundle ID: " .. info.CFBundleIdentifier)
end
app.plist.write(path, data)
Write a plist file (XML format).
Parameters:
path(string) - File pathdata(table) - Data to write
Returns: boolean - Whether successful
app.plist.write("/path/to/config.plist", {
AppName = "MyApp",
Version = "1.0.0",
Settings = {
Theme = "dark",
AutoSave = true
}
})
app.plist.getValue(path, keyPath)
Read a single value from a plist file.
Parameters:
path(string) - Plist file pathkeyPath(string) - Key path (supports dot-separated nested paths)
Returns: any|nil - Value or nil
local version = app.plist.getValue(
"/Applications/Safari.app/Contents/Info.plist",
"CFBundleShortVersionString"
)
-- Nested path
local setting = app.plist.getValue("/path/to/config.plist", "Settings.Theme")
-- Array index (0-based)
local firstItem = app.plist.getValue("/path/to/config.plist", "Items.0")
app.plist.setValue(path, keyPath, value)
Set a single value in a plist file.
Parameters:
path(string) - Plist file pathkeyPath(string) - Key pathvalue(any) - Value (nil deletes the key)
Returns: boolean - Whether successful
app.plist.setValue("/path/to/config.plist", "LastOpened", os.time())
-- Set a nested value
app.plist.setValue("/path/to/config.plist", "Settings.Theme", "light")
-- Delete a key
app.plist.setValue("/path/to/config.plist", "OldKey", nil)
Type Mapping
| Plist Type | Lua Type |
|---|---|
| dict | table (hash map) |
| array | table (array) |
| string | string |
| integer/real | number |
| true/false | boolean |
| data | string (Base64 encoded) |
| date | string (ISO 8601 format) |
Examples
Read Application Info
function MyPlugin:getAppInfo(appPath)
local infoPath = app.path.join(appPath, "Contents/Info.plist")
if not app.path.exists(infoPath) then
return nil
end
local info = app.plist.read(infoPath)
if not info then
return nil
end
return {
name = info.CFBundleName or info.CFBundleDisplayName,
version = info.CFBundleShortVersionString,
build = info.CFBundleVersion,
bundleId = info.CFBundleIdentifier,
minOS = info.LSMinimumSystemVersion
}
end
function MyPlugin:handleShowAppInfo(context)
for _, file in ipairs(context.selectedFiles) do
if app.path.extension(file) == "app" then
local info = self:getAppInfo(file)
if info then
local message = string.format(
"Name: %s\nVersion: %s (%s)\nBundle ID: %s",
info.name or "Unknown",
info.version or "Unknown",
info.build or "Unknown",
info.bundleId or "Unknown"
)
app.dialog.alert({title = info.name, message = message})
end
end
end
end
Modify Configuration File
function MyPlugin:handleToggleSetting(context)
local configPath = "/path/to/config.plist"
-- Read current value
local enabled = app.plist.getValue(configPath, "Settings.Enabled")
-- Toggle and save
app.plist.setValue(configPath, "Settings.Enabled", not enabled)
app.notification.show("Settings", enabled and "Disabled" or "Enabled")
end