我怎样才能添加阵列使用PlistBuddy一个的plist? [英] How can I add an Array to a Plist using PlistBuddy?
问题描述
这问题是一个子问题/替代的方式来接近我试图通过这个问题做:<一href=\"http://stackoverflow.com/questions/15562946/how-can-i-use-plistbuddy-to-copy-an-entry-from-one-file-to-another\">How我可以用PListBuddy一个条目从一个文件复制到另一个?
This question is a Sub-Question/Alternative Way to approach what I am trying to do via this question: How can I use PListBuddy to copy an entry from one file to another?
我想通过一个X code复制从plist文件A到使用PlistBuddy plist文件b条目构建脚本,使用bash /壳牌。通过这样做,我不能使用PlistBuddy的复制功能。我必须在每个单独的入口复制了所有它的元素,因为你不能添加/套字典,但必须通过条目与PlistBuddy交互。
I want to copy an Entry from Plist File A to Plist File B using PlistBuddy through an XCode Build Script, using Bash/Shell. By doing this, I cannot use PlistBuddy's "Copy" function. I must copy each individual entry over with all of it's elements, since you cannot add/set dictionaries, but must interact with PlistBuddy via "Entries".
我所试图做的是采取plist文件A和存储其标题/值数组的PSMultiValueSpecifier元素。我能够抢在数组中的元素,并将其打印到屏幕上,但是当我去给他们添加到目标plist文件B,数组仍然是空的。
What I am trying to do is take Plist File A and store its Titles/Values Arrays for a "PSMultiValueSpecifier" element. I am able to grab the elements in the arrays and print them to the screen, but when I go to add them into the destination Plist file B, the arrays are still empty.
code:(code抢分录添加)
Code: (Code to Grab the Entry for Adding)
# Configure the Entry
${PLISTBUDDY} -c "Add PreferenceSpecifiers:$DEST_INDEX dict" ${DEST_PLIST}
${PLISTBUDDY} -c "Add PreferenceSpecifiers:$DEST_INDEX:Type string 'PSMultiValueSpecifier'" ${DEST_PLIST}
# Retrieve the Additional Field Value
preferenceTitle=`$PLISTBUDDY -c "Print PreferenceSpecifiers:$SOURCE_INDEX:Title" $SOURCE_PLIST 2>&1`
preferenceKey=`$PLISTBUDDY -c "Print PreferenceSpecifiers:$SOURCE_INDEX:Key" $SOURCE_PLIST 2>&1`
preferenceDefaultValue=`$PLISTBUDDY -c "Print PreferenceSpecifiers:$SOURCE_INDEX:DefaultValue" $SOURCE_PLIST 2>&1`
preferenceValues=`$PLISTBUDDY -c "Print PreferenceSpecifiers:$SOURCE_INDEX:Values" $SOURCE_PLIST 2>&1`
preferenceTitles=`$PLISTBUDDY -c "Print PreferenceSpecifiers:$SOURCE_INDEX:Titles" $SOURCE_PLIST 2>&1`
code以添加新条目:
Code to Add the new Entry:
# Set the Additional Field Values
${PLISTBUDDY} -c "Add PreferenceSpecifiers:$DEST_INDEX:Title string $preferenceTitle" ${DEST_PLIST}
${PLISTBUDDY} -c "Add PreferenceSpecifiers:$DEST_INDEX:Key string $preferenceKey" ${DEST_PLIST}
${PLISTBUDDY} -c "Add PreferenceSpecifiers:$DEST_INDEX:DefaultValue integer $preferenceDefaultValue" ${DEST_PLIST}
####BORKEN####
${PLISTBUDDY} -c "Add PreferenceSpecifiers:$DEST_INDEX:Values array $preferenceValues" ${DEST_PLIST}
${PLISTBUDDY} -c "Add PreferenceSpecifiers:$DEST_INDEX:Titles array $preferenceTitles" ${DEST_PLIST}
####BORKEN####
下面是code的片段产生以下数据:
Here is a snippet of Code that produces the below data:
echo "#########"
echo "[$THIS] adding $preference: $preferenceDict"
echo "#########"
echo "Source: "`$PLISTBUDDY -c "Print PreferenceSpecifiers:$SOURCE_INDEX:Values" $SOURCE_PLIST`
echo "Source: "`$PLISTBUDDY -c "Print PreferenceSpecifiers:$SOURCE_INDEX:Titles" $SOURCE_PLIST`
echo "#########"
echo "Destination: "`$PLISTBUDDY -c "Print PreferenceSpecifiers:$DEST_INDEX:Values" $DEST_PLIST`
echo "Destination: "`$PLISTBUDDY -c "Print PreferenceSpecifiers:$DEST_INDEX:Titles" $DEST_PLIST`
echo "#########"
下面是证明正确的字段都被运提供的数据
Here is the data provided proving that the proper fields are being transported
#########
[addDebugSettingsMenu.bash] adding : Dict {
Titles = Array {
Meters
Feet
}
DefaultValue = 1
Values = Array {
1
2
}
Key = UserPreferences_UnitsKey
Type = PSMultiValueSpecifier
Title = Units
}
#########
Source: Array { 1 2 }
Source: Array { Meters Feet }
#########
Destination: Array { }
Destination: Array { }
#########
如果您有关于PlistBuddy无证功能的知识请大家帮帮忙。手册页是超薄和例子都远远之间。
Please help if you have any knowledge regarding undocumented features of PlistBuddy. The MAN pages are super slim and examples are far and between.
我要感谢你读这篇文章,借给你的大脑,以帮助我在我的脖子上解决这一重大难题。
I would like to thank you for reading this and for lending your brains to help me solve this major pain in my neck.
推荐答案
有可能是一个更好的方式来做到这一点,但我已经源数组中的计数的元素,然后分别将它们复制在解决了这个问题。
There may be a better way to do this, but I have solved this problem by counting the elements in the source array and then copying them over individually.
${PLISTBUDDY} -c "Add PreferenceSpecifiers:$DEST_INDEX:Titles array" ${DEST_PLIST}
${PLISTBUDDY} -c "Add PreferenceSpecifiers:$DEST_INDEX:Titles:0 string 'TITLE_1'"
${DEST_PLIST} ${PLISTBUDDY} -c "Add PreferenceSpecifiers:$DEST_INDEX:Titles:1 string 'TITLE_2'" ${DEST_PLIST}
etc...
这篇关于我怎样才能添加阵列使用PlistBuddy一个的plist?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!