advertisement

Article:
  Scripting Mac OS X
Subject:   more difficult defaults
Date:   2003-11-14 13:01:50
From:   jamesreynolds
Response to: more difficult defaults

I believe defaults can only read the first key, in the case of com.apple.internetconfig, it would be "Version 2.5.3" in Jaguar and "Version 2.5.4" in Panther. Then it prints out the entire preference basically. I would love to know that I am wrong, because then it makes alot of things possible, but I don't think I am wrong.


Because defaults can only read the first key, you would have to get the entire output of the preference file, parse it, make your change, then save it again. This is much easier to do with Cocoa or even CoreFoundation (maybe easier...).


The defaults utility is just a really simple XML reader/writer. "Really simple" can not be emphasized, and you know this if you have used a real xml parser. See http://www.xml.com/.


There is an XML parser for perl, and Python parses XML also. However, neither of them parse XML out of the box. The XML perl module has to be downloaded from CPAN. I think the source code might even need to be tweaked with to get it to compile--see some recent posts to the macosx@perl.org mail list. I believe Python is missing some libraries (I'm guessing here from what I remember seeing on some lists). This was Jaguar also.


In summary, I know of no easy "out-of-the-box" way to read/write XML from a script. If anyone knows, please post.


When I have complex preference I need to change, I just open and read the raw xml file, find what I want to change, change it (writing raw xml) and then save it.


But here is what will really stop you from doing what you want. The DownloadFolder key has a dictionary with one item: the key "ic-data" and its data. The data probably represents an alias, but I am not sure.


So since the preference file doesn't store the download location as a path, that doesn't leave much option for scripting because AFAIK, there is no way via command line to create or get a textual representation of an alias.


Well, ok. I have a tool that will do this for the dock, but it isn't public yet. And it only works for the dock right now. No time frame for the release other than "not soon"


1 to 1 of 1
  1. more difficult defaults
    2004-03-04 14:49:26  yantheman [View]

1 to 1 of 1