title: How do I use "defaults write" correctly from pkgbuild / productbuild?
body: <p>I'm building an installer package with</p>
  
  <pre><code>pkgbuild --component MyApp.app ... --scripts scriptsdir MyApp.pkg
  </code></pre>
  
  <p>And I would like to set some user defaults after installation. So I made a <code>postinstall</code> script with:</p>
  
  <pre><code>defaults write com.mycompany.MyApp key -string value
  </code></pre>
  
  <p>However, this doesn't work — the settings get written to <code>/var/root/Library/Preferences</code>, and are only accessible by <code>sudo defaults read</code>.</p>
  
  <p>So instead I tried this:</p>
  
  <pre><code>defaults write ~/Library/Preferences/com.mycompany.MyApp key -string value
  </code></pre>
  
  <p>Now they get written to the right place, but the permissions are wrong — <code>stat</code> shows the permissions on the plist file are <code>-rw------- 1 root wheel</code>, and <code>defaults read</code> can't access them. How can I get this to work correctly?</p>