Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Is there an Apple Script that enables the user to extract the total count of mails from each mailbox in Mac Mail

This is the output I would like to generate


Mailbox name # of emails

Project 1 65

Project 2 89

Project 3 21

Mac mini

Posted on May 26, 2015 1:49 AM

Reply
Question marked as Best reply

Posted on May 26, 2015 9:10 AM

Hello


You may try something like this.



_main() on _main() script o property |MAILBOX_PATH| : false -- true to get mailbox path, false to get mailbox name property pp : {} property qq : {{"Mailbox", "# of emails"}} tell application "Mail" set pp to mailboxes repeat with p in my pp tell p's contents if |MAILBOX_PATH| then set my qq's end to {(it as record)'s «class seld», count messages} else set my qq's end to {name, count messages} end if end tell end repeat end tell set t to _array2text(qq, tab, linefeed) --set the clipboard to t return t end script tell o to run end _main on _array2text(aa, fs, rs) (* list aa : source 2d-array string fs : column separator (field separator) string rs : row separator (record separator) return string : text representation of aa *) script o property pp : aa property qq : {} repeat with p in my pp set end of my qq to _join(p's contents, fs) end repeat return _join(qq, rs) end script tell o to run end _array2text on _join(tt, d) (* list tt : source list string d : separator return string : tt joined with d *) local astid0, t try set {astid0, AppleScript's text item delimiters} to {AppleScript's text item delimiters, {} & d} set t to "" & tt set AppleScript's text item delimiters to astid0 on error errs number errn set AppleScript's text item delimiters to astid0 error errs number errn end try return t end _join




Briefly tested with Mail 4.6 under OS X 10.6.8.


Good luck,

H

1 reply
Question marked as Best reply

May 26, 2015 9:10 AM in response to Eddieno8

Hello


You may try something like this.



_main() on _main() script o property |MAILBOX_PATH| : false -- true to get mailbox path, false to get mailbox name property pp : {} property qq : {{"Mailbox", "# of emails"}} tell application "Mail" set pp to mailboxes repeat with p in my pp tell p's contents if |MAILBOX_PATH| then set my qq's end to {(it as record)'s «class seld», count messages} else set my qq's end to {name, count messages} end if end tell end repeat end tell set t to _array2text(qq, tab, linefeed) --set the clipboard to t return t end script tell o to run end _main on _array2text(aa, fs, rs) (* list aa : source 2d-array string fs : column separator (field separator) string rs : row separator (record separator) return string : text representation of aa *) script o property pp : aa property qq : {} repeat with p in my pp set end of my qq to _join(p's contents, fs) end repeat return _join(qq, rs) end script tell o to run end _array2text on _join(tt, d) (* list tt : source list string d : separator return string : tt joined with d *) local astid0, t try set {astid0, AppleScript's text item delimiters} to {AppleScript's text item delimiters, {} & d} set t to "" & tt set AppleScript's text item delimiters to astid0 on error errs number errn set AppleScript's text item delimiters to astid0 error errs number errn end try return t end _join




Briefly tested with Mail 4.6 under OS X 10.6.8.


Good luck,

H

Is there an Apple Script that enables the user to extract the total count of mails from each mailbox in Mac Mail

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.