Ask Different is a question and answer site for power users of Apple hardware and software. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am trying to create file containing different statistics about things such as email count and such things, trial here: this proto returns empty file, not sure why. How can count the amount of emails with Automator under OS X?

share|improve this question

Probably easier to do this with AppleScript, which you can then use in an Automator action if you like.

tell application "Mail"
    set myAccount to "Gmail"
    set mailboxList to {"INBOX", "[Gmail]/Sent Mail"}
    set messageCount to 0
    repeat with _mailbox in mailboxList
        set messageCount to messageCount + (count of messages in mailbox _mailbox of account myAccount)
    end repeat
    get messageCount
end tell

That will return the number of messages in each mailbox you specify in the list on line two. If use it in an Automator action, it will pass that value along to whatever the next action is.

You'll need to change the myAccount line to whatever your account is named in preferences.

To get the specific mailbox names, run tell application "Mail" to get mailboxes of account "Gmail" in AppleScript editor. You can then add them to the mailboxList in line 3, make sure they're quoted, and each entry is separated by a comma.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.