nrs*_*ser 6 git macos plist defaults
我如何解析 OS X 的输出 defaults read
终端命令?
它似乎输出“旧的”NeXTSTEP plist 格式;看起来像的东西:
{
"Apple Global Domain" = {
AppleAntiAliasingThreshold = 4;
AppleCollationOrder = root;
Run Code Online (Sandbox Code Playgroud)
我尝试将输出写入文件并使用 转换plutil
,但它窒息:
> defaults read > defaults.txt
> plutil -convert xml1 defaults.txt
2014-02-02 21:29:14.856 plutil[56896:707] CFPropertyListCreateFromXMLData(): Old-style
plist parser: missing semicolon in dictionary on line 10835. Parsing will be abandoned.
Break on _CFPropertyListMissingSemicolon to debug.
defaults.txt: Property List error: Unexpected character { at line 1 / JSON error: No
value for key in object around character 28.
Run Code Online (Sandbox Code Playgroud)
我想将默认值存储在 git 中,以便我可以在应用更改后保留记录作为更改设置和差异,但似乎序列化defaults read
不是“行序稳定”:字典不会以一致的顺序转储它们的键,产生巨大的噪音。如果我可以解析defaults read
,然后我可以通过顺序一致的序列化程序将数据输出。
plutil可以转换为xml或json
#!/bin/bash
f='~/Library/Preferences/com.apple.LaunchServices/com.apple.launchservices.secure'
x="$(plutil -convert xml1 -o - "$f")"
j="$(plutil -convert json -o - "$f")"
Run Code Online (Sandbox Code Playgroud)
-o -
意思是:打印结果到stdout
$f
就是plist格式的输入文件
归档时间: |
|
查看次数: |
2685 次 |
最近记录: |