|
|
#1 |
|
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 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. |
|
|
|
|
|
#2 |
|
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.
|
|
|
|
|
|
#3 |
|
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
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' 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. |
|
|
|
|
|
#4 |
|
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. |
|
|
|
![]() |
|
|