Servers Enterprise
Q: How do I add to this plist?
There is a plist file that I want to add an entry to, if the entry already exists I also don't want to cause a duplicate of it to appear. This is what the plist file current would look like.
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <plist version="1.0"> <array> <dict> <key>Folder Name</key> <string>Birthday</string> </dict> <dict> <key>Folder Name</key> <string>Announcements</string> </dict> <dict> <key>Folder Name</key> <string>Photos</string> </dict> <dict> <key>Contains Original Stationery</key> <string>yes</string> <key>Folder Name</key> <string>Stationery</string> </dict> <dict> <key>Folder Name</key> <string>Sentiments</string> </dict> </array> </plist>
I want to add another entry of
<dict> <key>Folder Name</key> <string>My Folder</string> </dict>
So the new file should look like
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <plist version="1.0"> <array> <dict> <key>Folder Name</key> <string>My Folder</string> </dict> <dict> <key>Folder Name</key> <string>Birthday</string> </dict> <dict> <key>Folder Name</key> <string>Announcements</string> </dict> <dict> <key>Folder Name</key> <string>Photos</string> </dict> <dict> <key>Contains Original Stationery</key> <string>yes</string> <key>Folder Name</key> <string>Stationery</string> </dict> <dict> <key>Folder Name</key> <string>Sentiments</string> </dict> </array> </plist>
In OS X as standard there are two commands for modifying plist files, these are /usr/bin/defaults and /usr/libexec/PlistBuddy I would be happy to use either or any other built-in command but ideally it needs to be something built-in.
Many thanks for any help.
Posted on Aug 8, 2014 4:00 PM
