Go Back   The macosxhints Forums > OS X Help Requests > System



Reply
 
Thread Tools Rate Thread Display Modes
Old 11-30-2005, 10:24 AM   #1
Appleski
Prospect
 
Join Date: Nov 2005
Posts: 2
How can I change value of a key in nested dictionary using defaults cmd?
I tried something like:
Code:
defaults write com.mypfile Dict_1 -dict Dict_2 -dict myKey myVal
but I get:
Cannot nest composite types (arrays and dictionaries); exiting

For example, I want to edit Change key in com.apple.desktop.plist, which is in default Dictionary of Background Dictionary.
Appleski is offline   Reply With Quote
Old 11-30-2005, 12:36 PM   #2
giskard22
Moderator
 
Join Date: May 2003
Posts: 4,272
Not that this is really helpful, but in my experience -- and in what I've read online -- the defaults command is fairly useless when attempting to edit keys that are nested more than one level. You may need to try parsing the XML directly.
giskard22 is offline   Reply With Quote
Old 11-30-2005, 12:38 PM   #3
bramley
MVP
 
Join Date: Apr 2004
Location: Cumbria, UK
Posts: 2,461
There is quite a lot that can't be done with defaults easily or at all - and dealing with nested objects is certainly not its strong point.

It might be possible to get what you want by reading the top-level dictionary - to use your example:

Code:
defaults read com.apple.desktop Background
will give a text string that represents all the contents of the dictionary.

Then you would need to do a bit of text manipulation to substitute your value for the relevant key, and write it back to the plist i.e

Code:
defaults write com.apple.desktop Background 'altered text goes here'
There is an example in 'man defaults' although much simpler than you would need to implement. It is possible that such an attempt is too complicated for defaults. 'man defaults' does warn users that not all things are possible with the command.

You might want to look at Applescript, which has a plist manipulator (on Tiger) in the 'System Events' dictionary. I have not tried to use this so am unable to advise further.
bramley is offline   Reply With Quote
Old 12-01-2005, 11:11 AM   #4
Appleski
Prospect
 
Join Date: Nov 2005
Posts: 2
Thanks,
I wanted to make things simple.
read/edit/write method works, but when plist is large it's very difficult, escpecially when you are trying to write universal cmd for others to use.

I guess Property List Editor is the tool to use.
Appleski is offline   Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump



All times are GMT -5. The time now is 05:28 PM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.
Site design © IDG Consumer & SMB; individuals retain copyright of their postings
but consent to the possible use of their material in other areas of IDG Consumer & SMB.