PlistBuddy is the shiznit..
Friday, July 14th, 2006So I’ve been meaning to start using PlistBuddy for a while, and this morning I ran into a real need for it.
Unbeknownst to me, we had a problem with our imaging system where a machine would be freshly imaged, and it would retain the LocalHostName and ComputerName of the imaged machine until the next reboot.
(We normally set these values to “hostname -s” as part of a StartupItem)
Anyway, I wanted to set these values when machines are booted from our custom NetInstall image, and quite frankly, using “defaults” with nested dictionaries can sometimes either be an absolute pain in the ass, or impossible.
Obviously someone at Apple realised this a while ago, which is why they invented PlistBuddy. If you do “locate PlistBuddy” from a shell, you’re likely to see it in all sorts of Apple packages, and I feel perfectly comfortable simply stealing one of them…
PlistBuddy lets you easily write nested values and merge dictionaries into each other.
Here’s the two liner that lets you set the relevant values (as root/sudo etc)
$ PlistBuddy -c "Set :System:Network:HostNames:LocalHostName $(hostname -s)" \ /Library/Preferences/SystemConfiguration/preferences.plist $ /PlistBuddy -c "Set :System:System:ComputerName $(hostname -s)" \ /Library/Preferences/SystemConfiguration/preferences.plist
And for us we just point it to /Volumes/System/Library/… etc as that’s where the SOE partition is while NetBooting.
Much nicer than using defaults…