问题描述
在我的Info.plist
文件中,我想修改外壳上的Plist文件,如下所示:
In my Info.plist
file I want to modify a Plist file on the shell which looks like this:
<plist version="1.0">
<dict>
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleURLName</key>
<string>urlname-1</string>
</dict>
</array>
</dict>
</plist>
现在,我想使用PlistBuddy使其看起来像这样,并在CFBundleURLSchemes
键中添加一个字符串数组值(或其他所有值):
Now I want to make it look like this using PlistBuddy, adding the CFBundleURLSchemes
key with a string-array value (or every other value):
<plist version="1.0">
<dict>
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleURLName</key>
<string>urlname-1</string>
<key>CFBundleURLSchemes</key>
<array>
<string>urlscheme-1</string>
</array>
</dict>
</array>
</dict>
</plist>
如何通过PlistBuddy实现这一目标?
How can I achieve this with PlistBuddy?
假定CFBundleURLTypes
的数组值为空:通过执行/usr/libexec/PlistBuddy -c "Add :CFBundleURLTypes:0:CFBundleURLName string 'urlname-1'" Info.plist
,我可以将字典添加到包含第一个键/值对的数组中:
Assumed the array value of CFBundleURLTypes
would be empty:By executing /usr/libexec/PlistBuddy -c "Add :CFBundleURLTypes:0:CFBundleURLName string 'urlname-1'" Info.plist
I'm able to add the dictionary into the array including it's first key/value pair:
<plist version="1.0">
<dict>
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleURLName</key>
<string>urlname-1</string>
</dict>
</array>
</dict>
</plist>
但是我不知道如何将第二个键(例如带有字符串数组值的CFBundleURLSchemes
)放入同一字典中.
But I don't know how to get the second key, eg CFBundleURLSchemes
with a string-array value into the same dictionary.
有人可以给我指点吗? PlistBuddy可以做到吗?
Can anyone give me a pointer? Is this possible with PlistBuddy at all?
推荐答案
不确定这是否是您期望的命令...
Not sure if this is the command you're expecting...
/usr/libexec/PlistBuddy -c "clear dict" -c "add :CFBundleURLTypes array" -c "add :CFBundleURLTypes:0 dict" -c "add :CFBundleURLTypes:0:CFBundleURLName string 'urlname-1'" -c "add :CFBundleURLTypes:0:CFBundleURLSchemes array" -c "add :CFBundleURLTypes:0:CFBundleURLSchemes:0 string urlscheme-1" Info.plist
这篇关于如何使用PlistBuddy将多个条目添加到plist词典的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!