Re: defaults write vs PlistBuddy vs Something Else??
Re: defaults write vs PlistBuddy vs Something Else??
- Subject: Re: defaults write vs PlistBuddy vs Something Else??
- From: Allister Banks <email@hidden>
- Date: Mon, 13 Dec 2010 23:21:54 -0500
Hey Mr. Cook,
PlistBuddy could theoretically be embraced as a successor to defaults, but while it is nice for the quick one-off command, a combination of plutil(to convert binary to human-readable xml) and a scripting language that has libraries or built-in functions to modify text in an optimized fashion would of course be the more programmatic way to get the job done.
There's a great article in MacTech on using python to manipulate plists(10.5, or python 2.5 and higher to utilize PyObjC), and there's a whole book by MacTech editor Ed Marczak on the subject of managed preferences. For a somewhat... advanced example of using python with plists, there is this post by Karl Kuehn:
http://wranglingmacs.blogspot.com/2010/05/using-plists-from-python.html
Ruby has emerged as a first-class Mac citizen with the open source MacRuby project(http://www.macruby.org), and has even better access to native Objective-C functionality. It appears to be less in use to fulfill this need(or at least documented) than python for some reason, however.
Allister Banks
POINT
www.pointconsultants.com
646.502.4708
368 Broadway Ste. 303
New York, New York 10013
On Dec 13, 2010, at 8:21 PM, Paul Cook wrote:
>
> I'm confused by what seem, to me at least, to be very mixed messages coming from Apple concerning which tools we should use to create and edit plists. And I'm wondering if anyone in this list might have greater clarity than I seem to have.
>
> defaults write
> Figuring out how to do complicated plists with a defaults write command can be a bit of a challenge. However, it does seem to work and is is installed in all recent versions of OS-X. The concern is that the man page for has the following nice little warning in it:
>
> WARNING: The defaults command will be changed in an upcoming
> major release to only operate on preferences domains. General
> plist manipulation utilities will be folded into a different
> command-line program.
>
> It is nice of Apple to give us a warning, but it would be nicer, if they would tell us both when to expect such functionality to cease (Lion, Furball, Calico, Tabby, etc.) and to which program we should switch. (Does the replacement even exist yet??)
>
> PlistBuddy
> PlistBuddy is one of the candidates for replacement. If one opens a terminal window and types "PlistBuddy -h", the result is "-bash: PlistBuddy: command not found". PlistBuddy isn't even in the default command path. And while one could do damage to their system with PlistBuddy, they could with defaults write and even lots of other commands such as "rm", so that doesn't appear to be the reason. A "man PlistBuddy" does at least return some information, but not where it is.
>
> My Snow Leopard machine does have a copy at /usr/libexec/PlistBuddy. But Googling the Internet for PlistBuddy, one finds suggestions for it in other locations and at least one suggestion that you ought to do a "locate PlistBuddy" to find it. (Assuming that you can count on that database having been built.) But it appears that there is uncertainty as to when and where you could first count on having PlistBuddy on a machine. And I've seen more than one suggestion that you should provide your own copy. That would seem to imply distributing Apple code, which I'm not sure we should be doing.
>
> If PlistBuddy is to be the heir, Apple certainly didn't make it apparent.
>
> Question
> So what should one use in scripts?
>
> Best Wishes,
>
> Paul _______________________________________________
> Do not post admin requests to the list. They will be ignored.
> Installer-dev mailing list (email@hidden)
> Help/Unsubscribe/Update your Subscription:
>
> This email sent to email@hidden
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Installer-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden