PlistBuddy
是 Mac
自带的专门解析 plist
的工具,由于 PlistBuddy
并未在 Mac
中默认配置,所以需要通过绝对路径来引用,PlistBuddy
的路径所在:
/usr/libexec/PlistBuddy
示例演示
代码
NSServices
Array {
Dict {
NSMessage = decompressFiles
NSKeyEquivalent = Dict {
default = X
}
NSPortName = MacZip
NSRequiredContext = Dict {
NSTextContent = FilePath
}
NSMenuItem = Dict {
default = Decompress with MacZip
}
}
Dict {
NSMenuItem = Dict {
default = Compress with MacZip
}
NSRequiredContext = Dict {
NSTextContent = FilePath
}
NSSendTypes = Array {
NSFilenamesPboardType
public.directory
}
NSPortName = MacZip
NSSendFileTypes = Array {
public.content
public.directory
}
NSMessage = compressFiles
NSKeyEquivalent = Dict {
default = Y
}
}
}
打印显示
cd desktop //进入info.plist所在文件夹
/usr/libexec/PlistBuddy -c 'Print :NSServices' info.plist //显示NSServices所有代码
/usr/libexec/PlistBuddy -c 'Print :NSServices:0' info.plist
结果:
Dict {
NSMessage = decompressFiles
NSKeyEquivalent = Dict {
default = X
}
NSPortName = MacZip
NSRequiredContext = Dict {
NSTextContent = FilePath
}
NSMenuItem = Dict {
default = Decompress with MacZip
}
}
//数组array中第一个Dict
/usr/libexec/PlistBuddy -c 'Print :NSServices:0:NSMenuItem' info.plist
结果:
Dict {
default = Decompress with MacZip
}
//NSMenuItem中的内容
/usr/libexec/PlistBuddy -c 'Print :NSServices:0:NSMenuItem:default' info.plist
结果:
Decompress with MacZip
//default对应的内容
修改参数
/usr/libexec/PlistBuddy -c 'set :NSServices:0:NSMenuItem:default "解压文件"' info.plist
结果:
Dict {
default = 解压文件
}
删除参数
/usr/libexec/PlistBuddy -c 'delete :NSServices:0:NSMenuItem:default' info.plist
结果:
Dict {
}
增加参数
/usr/libexec/PlistBuddy -c 'add :NSServices:0:NSMenuItem:test string hello' info.plist
结果:
Dict {
default = Decompress with MacZip
test = hello
}
文章评论