mind the explanatory gap

many a slip ‘twixt mind and lip…

mind the explanatory gap RSS Feed

PlistBuddy is the shiznit..

So 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…

4 Responses to “PlistBuddy is the shiznit..”

  1. nigel kersten Says:

    hmm.

  2. Jeff McCune Says:

    Here’s another example. Manage the IR receiver:

    PlistBuddy -c ‘Set :DeviceEnabled True’ /Library/Preferences/com.apple.driver.AppleIRController.plist

  3. Stu Says:

    A nice Applescript example of Plistbuddy usage

    http://bbs.applescript.net/viewtopic.php?id=18380

  4. Arek Dreyer Says:

    It looks like Plistbuddy in Leopard is now in a pretty short, easy, and consistent location: /usr/libexec/PlistBuddy

Leave a Reply