How can I use PlistBuddy to access an element of PreferencesSpecified by its property? How can I use PlistBuddy to access an element of PreferencesSpecified by its property? xcode xcode

How can I use PlistBuddy to access an element of PreferencesSpecified by its property?


#!/bin/tcshset 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    endifend


A little improvement to the geowar's answer. Get product version from Info.plist.

#!/bin/tcshset infoPlist="Info.plist"set version=`/usr/libexec/PlistBuddy -c "Print CFBundleShortVersionString" ${infoPlist}`set bundleVersion=`/usr/libexec/PlistBuddy -c "Print CFBundleVersion" ${infoPlist}`set productVersion=$version.$bundleVersion# echo "the product version is ${productVersion}."set settingsPlist="Settings.bundle/Root.plist"set settingsCnt=`/usr/libexec/PlistBuddy -c "Print PreferenceSpecifiers:" ${settingsPlist} | grep "Dict"|wc -l`# echo "the count is: $settingsCnt."set settingsCnt=`expr "$settingsCnt" '-' '1'`foreach idx (`seq 0 $settingsCnt`)    # echo "the index is: $idx."    set val=`/usr/libexec/PlistBuddy -c "Print PreferenceSpecifiers:${idx}:Key" ${settingsPlist}`    # echo "the value of PreferenceSpecifiers:${idx}:Title: is ${val}."    if ( "$val" == "version" ) then        echo "the index of the entry whose 'Key' is 'version' is $idx."        # now set it        /usr/libexec/PlistBuddy -c "Set PreferenceSpecifiers:${idx}:DefaultValue $productVersion" ${settingsPlist}        # just to be sure that it worked        set ver=`/usr/libexec/PlistBuddy -c "Print PreferenceSpecifiers:${idx}:DefaultValue" ${settingsPlist}`        echo 'PreferenceSpecifiers:$idx:DefaultValue set to: ' $ver    endifend