plutil 是 macOS 下的一个命令行工具,用于编辑和处理 *.plist 格式的文件。
转换文件格式
plutil -convert xml1 ToolchainInfo.plist
文件类型说明:xml1 XML 格式,binary1 二进制格式,json JSON 格式。
修改键值
ToolchainInfo.plist 文件的内容:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Identifier</key>
<string>com.apple.dt.toolchain.XcodeDefault</string>
</dict>
</plist>
把 Key Identifier 的值由 com.apple.dt.toolchain.XcodeDefault 改为 com.apple.dt.toolchain.Xcode11.3.1:
plutil -replace Identifier -string com.apple.dt.toolchain.Xcode11.3.1 ToolchainInfo.plist
使用 PlistBuddy
PlistBuddy 也是另一个编译 plist 文件的工具,但是不在 $PATH 路径中,它的路径是:
/usr/libexec/PlistBuddy
读取 plist 文件:
/usr/libexec/PlistBuddy -c "Print" ToolchainInfo.plist
设置 plist 中的某个键的值:
/usr/libexec/PlistBuddy -c "Add CompatibilityVersion integer 2" ToolchainInfo.plist
Add 是添加新键值,Set 是修改已有值。
