Can defaults write go more than one key deep?

548 Views Asked by At

I want to create a defaults write command go 2 levels deep, but can't find anything online.

The closest I got was 1 level deep using the -dict switch.

I want to script my OC update, so a lot of people could probably use this method, if I can get it to work, it would be a lot better than swapping the whole file in and out.

for example; defaults write ~/Desktop/config Kernel -dict Emulate -dict Cpuid1Mask -data AAAAAAAAAAAAAACAAAAAAA==

the second use of the -dict doesn't work, but this is what I am trying for...

I've tried just about everything I can think of, but can't get the syntax correct.

Maybe defaults write can't handle it, but I would like to do this with the defaults write command, and not have to install another command line tool.

I want to be able to change these values;

<plist version="1.0">
<dict>
    <key>Kernel</key>
    <dict>
        <key>Emulate</key>
        <dict>
            <key>Cpuid1Mask</key>
            <data>
            AAAAAAAAAAAAAAAAAAAAAA==
            </data>
        </dict>
    </dict>
    <key>PlatformInfo</key>
    <dict>
        <key>UpdateSMBIOS</key>
        <true/>
    </dict>
</dict>
</plist>
1

There are 1 best solutions below

0
On

If you encode all of it in the plist format you can do this:

defaults write ~/Desktop/config '<dict><key>Kernel</key><dict><key>Emulate</key><dict><key>Cpuid1Mask</key><data>AAAAAAAAAAAAAACAAAAAAA==</data></dict></dict><key>PlatformInfo</key><dict><key>UpdateSMBIOS</key><true/></dict></dict>'

If you want to format the plist nicely:

defaults write ~/Desktop/config '<dict>
  <key>Kernel</key>
  <dict>
    <key>Emulate</key>
    <dict>
      <key>Cpuid1Mask</key>
      <data>AAAAAAAAAAAAAACAAAAAAA==</data>
    </dict>
  </dict>
  <key>PlatformInfo</key>
  <dict>
    <key>UpdateSMBIOS</key>
    <true/>
  </dict>
</dict>'

If you're only trying to write the Kernel dict:

defaults write ~/Desktop/config Kernel '<dict><key>Emulate</key><dict><key>Cpuid1Mask</key><data>AAAAAAAAAAAAAACAAAAAAA==</data></dict></dict>'

If you want to format the plist nicely:

defaults write ~/Desktop/config Kernel '<dict>
    <key>Emulate</key>
    <dict>
        <key>Cpuid1Mask</key>
        <data>AAAAAAAAAAAAAACAAAAAAA==</data>
    </dict>
</dict>'