title: Mac OS X 10.10 Yosemite Bash script defaults read generates The domain/default pair of does not exist error
body: <p>I am trying to check the default homepage in Safari on Mac OS X 10.10 Yosemite.  </p>
  
  <p>On my vanilla system the homepage isn't actually set, so first I forcibly set the HomePage using command:</p>
  
  <pre><code>defaults write com.apple.Safari.plist HomePage www.google.co.uk
  </code></pre>
  
  <p>Now I can read the HomePage setting using this command:</p>
  
  <pre><code>defaults read com.apple.Safari.plist HomePage
  </code></pre>
  
  <p>www.google.co.uk</p>
  
  <p>is the output.</p>
  
  <p>I need to do this for the console user using a Bash Script that is delivered and executed by Microsoft SCCM.  The Microsoft SCCM Client runs under the machine's system account so running the defaults read command above does not report the logged-in user's setting.  To work around this I am using commands that first determine the logged-in user's userID and then another to read the HomePage value using a full path to the logged-in user's (if applicable) instance of the Safari plist file.</p>
  
  <p>If I execute the top four lines manually, the expected homepage is stored in variable myuserhompage and is displayed as expected.</p>
  
  <pre><code>myuser=$(stat -f%Su /dev/console)
  myuserhompage="$(defaults read /users/$myuser/library/preferences/com.apple.Safari HomePage)"
  if [[ ${myuserhompage} == "www.google.co.uk" ]] ;
  then
    echo "homepage_set"
    exit 0
  else
    echo "homepage_not_set"
    exit 1
  fi
  </code></pre>
  
  <p>However when I run the same lines of code from within a Bash script, I see The domain/default pair of does not exist error.</p>