gpt4 book ai didi

xcode - 如何使用 PlistBuddy 访问由其属性指定的 PreferencesSpecified 元素?

转载 作者:行者123 更新时间:2023-12-03 14:49:09 25 4
gpt4 key购买 nike

目前我正在使用此代码

  /usr/libexec/PlistBuddy -c "Set PreferenceSpecifiers:1:DefaultValue $productVersion" "Test/Settings.bundle/Root.plist"

在构建阶段的脚本部分,将产品版本放在应用程序设置的只读字段中。该字段具有首选项数组的位置 1(从 0 开始)。

我在问是否可以使用比 1 更强大的东西来访问该字段,因为我或其他开发人员在开发过程中可能会意外更改位置。

我可以访问指定它的标识符的元素而不管它的位置吗?

为了更好地说明我的需求,我写了一个例子。我需要输入类似 1.2.345 的内容进入 string第二个节点 dictarray即我需要从 0.0.0 改变至 1.2.345 .是否可以访问 dict节点而不说明它是数组中的第二个?我要求在 PlistBuddy 中使用类似于 xpath 表达式的东西(如果存在的话)。
<?xml version="1.0" encoding="UTF-8"?>
<dict>
<key>PreferenceSpecifiers</key>
<array>
<dict>
<key>Title</key>
<string>Application info</string>
<key>Type</key>
<string>PSGroupSpecifier</string>
</dict>
<dict>
<key>DefaultValue</key>
<string>0.0.0</string>
<key>Key</key>
<string>version</string>
<key>Title</key>
<string>Version</string>
<key>Type</key>
<string>PSTitleValueSpecifier</string>
</dict>
<dict>
<key>DefaultValue</key>
<string>0</string>
<key>Key</key>
<string>build</string>
<key>Title</key>
<string>Build</string>
<key>Type</key>
<string>PSTitleValueSpecifier</string>
</dict>
...

最佳答案

#!/bin/tcsh
set productVersion="1.2.345"
set theFile="~/Desktop/PlistBuddy/Root.plist"
set cnt=`/usr/libexec/PlistBuddy -c "Print PreferenceSpecifiers:" ${theFile} | grep "Dict"|wc -l`
# echo "the count is: $cnt."
set cnt=`expr "$cnt" '-' '1'`

foreach idx (`seq 0 $cnt`)
# echo "the index is: $idx."
set val=`/usr/libexec/PlistBuddy -c "Print PreferenceSpecifiers:${idx}:Title" ${theFile}`
# echo "the value of PreferenceSpecifiers:${idx}:Title: is ${val}."

if ( "$val" == "Version" ) then
echo "the index of the entry whose 'Title' is 'Version' is $idx."
# now set it
/usr/libexec/PlistBuddy -c "Set PreferenceSpecifiers:${idx}:DefaultValue $productVersion" ${theFile}

# just to be sure that it worked
set ver=`/usr/libexec/PlistBuddy -c "Print PreferenceSpecifiers:${idx}:DefaultValue" ${theFile}`
echo 'PreferenceSpecifiers:$idx:DefaultValue set to: ' $ver
endif
end

关于xcode - 如何使用 PlistBuddy 访问由其属性指定的 PreferencesSpecified 元素?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13970218/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com