How to read mail via command on Mac? I set my mail agent tool to send and to receive mails with many accounts such as a gmail account. 

I want to read the mail via command line for triggering cronjob purpose.

For example,  | grep "Subject: " &amp;&amp; echo "I got it." this one is my purpose.

Is there also a way to switch among those accounts' mail box for reading purpose?
This is to me to know AppleScript with shell script.

My purpose is to use this to check the hard drive size. 

I answer here.

#!/bin/bash
var=$(df -h / | tail -n 1 | awk '{print $4}' | sed 's|Gi||g'); 
checker=;

if [ ${var} -lt 40 ]; then 
  checker=0;
  echo "The space is less than 40 Gb."
else 
  checker=1;
  echo "The space is more than 40 Gb."
fi

if [ ${checker}=1 ]; then
  osascript &lt;&lt;'EOD'
tell application "Mail"
    set theFrom to “someone@gmail.com"
    set recipientName to ""
    set recipientAddress to “nobody@gmail.com"
    set theSubject to "The rest of hard drive space is less 40Gb"
    set theMessage to make new outgoing message with properties {sender:theFrom, subject:theSubject, visible:false}
    tell theMessage
        make new to recipient with properties {name:recipientName, address:recipientAddress}
        send
    end tell
end tell
EOD
fi