Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a plist file and I'm interested in fetching values from nested dictionaries using shell script. Here is the structure of my plist file:

           <string>Washington DC</string>
           <string>North America</string>

I'm interested in fetching value assigned to the "Capital" key if user supplies a Country name.
For e.g If I execute the following command,I get the complete data under the "Countries" dictionary.

defaults read "/Users/sameerp/Downloads/data" Countries  2>&1   

I get the following output:

Italy =     {
    Capital = Rome;
    Continent = Europe;
USA =     {
    Capital = "Washington DC";
    Continent = "North America";

How do I modify the command above to pass it the "Country" Key(USA for e.g.) and fetch the value for "Capital" Key

share|improve this question
So, what is your question? What do you have so far? You're not asking us to write the script for you right? – terdon Oct 12 '12 at 0:01
@terdon: I'm not asking anyone to write the script for me. I wanted to know if there is a direct way to access a key's value in nested dictionary using "defaults read" command. – smokinguns Oct 12 '12 at 0:15
+1, thanks for the update. – terdon Oct 12 '12 at 1:17
up vote 9 down vote accepted

defaults can't do this without a lot of mess, but PlistBuddy will:

/usr/libexec/PlistBuddy -c "print :Countries:USA:Capital" /Users/sameerp/Downloads/data.plist
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.