title: Command-line access to OS X's keychain - How to get e-mail address associated with account
body: <p>I'm writing a Bash command-line tool that accesses the keychain for emulating a web browser to communicate with web pages.</p>
  
  <p>It's quite straightforward to get the password stored in the keychain from there:</p>
  
  <pre><code>PASSWORD=`security find-internet-password -gs accounts.google.com -w`
  </code></pre>
  
  <p>But it's a bit more tricky to extract the email address, as the most specific command you get for this returns a lot of information:</p>
  
  <pre><code>$security find-internet-password -gs accounts.google.com
  /Users/me/Library/Keychains/login.keychain"
  class: "inet"
  attributes:
      0x00000007 &lt;blob&gt;="accounts.google.com"
      0x00000008 &lt;blob&gt;=&lt;NULL&gt;
      "acct"&lt;blob&gt;="my-email-address@gmail.com"
      "atyp"&lt;blob&gt;="form"
      "cdat"&lt;timedate&gt;=0x32303135303333303134333533315A00  "20150330143531Z\000"
      "crtr"&lt;uint32&gt;="rimZ"
      "cusi"&lt;sint32&gt;=&lt;NULL&gt;
      "desc"&lt;blob&gt;=&lt;NULL&gt;
      "icmt"&lt;blob&gt;=&lt;NULL&gt;
      "invi"&lt;sint32&gt;=&lt;NULL&gt;
      "mdat"&lt;timedate&gt;=0x32303135303333303134333533315A00  "20150330143531Z\000"
      "nega"&lt;sint32&gt;=&lt;NULL&gt;
      "path"&lt;blob&gt;="/ServiceLogin"
      "port"&lt;uint32&gt;=0x00000000 
      "prot"&lt;blob&gt;=&lt;NULL&gt;
      "ptcl"&lt;uint32&gt;="htps"
      "scrp"&lt;sint32&gt;=&lt;NULL&gt;
      "sdmn"&lt;blob&gt;=&lt;NULL&gt;
      "srvr"&lt;blob&gt;="accounts.google.com"
      "type"&lt;uint32&gt;=&lt;NULL&gt;
  password: "my-password"
  </code></pre>
  
  <p>How would you extract the account e-mail address from the line starting with <code>"acct"&lt;blob&gt;=</code> and store it, say, to a variable called <code>EMAIL</code>?</p>