I have two previous posts about using Plistbuddy to add to an array in a .plist file (specifically Munki’s SelfServeManifest file):
Bash script to add optional installs for Munki
Terminal command to mark a Munki optional install for installation
What if you want to remove an item from the array? It’s not a simple thing to do. One option you have is to read the entire array, remove the offending entry, and then write back the modified array.
The most straightforward (but still roundabout) way I could think to do it is to find the index of the offending entry and then remove the entry by index number. Here’s an example:
acrobatDC=$(/usr/libexec/PlistBuddy -c “Print managed_installs” /Library/Managed\ Installs/manifests/SelfServeManifest | /usr/bin/grep -n “AdobeAcrobatDC” | /usr/bin/awk -F “:” ‘{print $1}’)
if [ ! -z “$acrobatDC” ]; then
# Item to delete is the number minus two
itemToDelete=$(($acrobatDC-2))
/usr/libexec/PlistBuddy -c “Delete :managed_installs:$itemToDelete” /Library/Managed\ Installs/manifests/SelfServeManifest
fi
So, assuming the variable is not empty, the item to delete is the line number minus 2, and then we can remove it by that index number.