0

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: " && echo "I got it." this one is my purpose.

Is there also a way to switch among those accounts' mail box for reading purpose?

  • You can set mail rules in macos mail to invoke a script. I know it's not from the command line, but should be able to do what you want. – historystamp Mar 6 at 4:29
  • Your going to need to install your own command line mail client. – historystamp Mar 6 at 4:31
  • Thanks. @historystamp I got it. I post an answer. – jefferyear Mar 10 at 11:48
1

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 <<'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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .