On Wed, May 12, 2010 at 10:00 AM, Federico Lucifredi <[email protected]> wrote: > The defaults are programmatically accessible from the shell "default" > command, for example: > > $ defaults read com.apple.iCal > > and the one I was after turns put to be simply: > > $ #check box -- 0 for uncheck > $ defaults write com.apple.iCal 'Disable all alarms' 1
Right, this is the straightforward way to do these things, when you can get away with it. Each invocation of the `defaults` command ends up poking a .plist file, which will typically be in one of (in order of increasing generality): • ~/Library/Preferences/ • /Library/Preferences/ • /System/Library/Preferences/ • /Network/Library/Preferences/ The problem is that a simple .plist file is a simple list of key/value pairs, for which `defaults` is a perfectly good approach. But in the format supports arbitrarily complex nesting of keys, dicts (hashes), arrays, etc, and the syntax for driving these from `detaults` can get really hairy, really fast. Enter PlistBuddy, found outside the standard path in /usr/libexec on recent OSX versions. Prior to 10.5, Apple frequently distributed it with package installers, so you'd typically end up with multiple copies of it buried somewhere under /Library/Receipts; starting with 10.5 though, it's part of the base system, albeit not in the default shell path for some reason. PlistBuddy lets you do arbitrarily complex "XPath style" queries on plist files. If you grow beyond `defaults` -- and for anything non-trivial, you will -- PlistBuddy is the tool to use: Man page: http://developer.apple.com/mac/library/DOCUMENTATION/Darwin/Reference/ManPages/man8/PlistBuddy.8.html Using it to add items to the Dock: http://www.macgeekery.com/tips/cli/adding_items_to_login_items_from_the_cli Convoluted examples of calling it from Applescript: http://macscripter.net/viewtopic.php?id=18380 Or, if you want to use Perl, use PerlObjCBridge (aka Foundation), which should be built in to recent Mac versions, and gives Perl programs full access to the Cocoa object library, including the methods for interacting with plist data: http://macdevcenter.com/lpt/a/6080 http://data.scl.utah.edu/fmi/xsl/stream/details.xsl?-recid=423&a::v=Ey12iE2EO2 Or it looks like there's a Data::Plist on CPAN now; I didn't notice it the last time I was looking into this, and don't know much about it. http://search.cpan.org/~KYOKI/Data-Plist-0.1/lib/Data/Plist.pm -- Chris Devers _______________________________________________ Boston-pm mailing list [email protected] http://mail.pm.org/mailman/listinfo/boston-pm

