The code I use is for an entirely different purpose and would probably be more confusing than instructive.
But I can make some general comments that may be instructive.
1. I get the name of the mailbox.
2. I look at the account of the mailbox.
3. I eliminate some mailboxes not "On My Mac".
Here's the script for steps 1, 2 and 3 ...
tell application "Mail"
try
set mailboxName to (name of mbox) as Unicode text
unread count of mbox -- "On My Mac" mailboxes always return this, Notes, RSS and ToDos do not.
on error
return 4 --> RSS or Reminder or Note
end try
try
account of mbox -- currently, this fails if mbox belongs to an imap account
set acnt to the result -- and errors here because acnt is undefined.
-- if (account type of acnt) is not pop then return 0 -- an imap account
account type of acnt
return 0 -- No Action
end try
if mbox is sent mailbox then return 0 --> No Action
if mbox is inbox then return 0 --> No Action
if mailboxName starts with "Sent Messages" then return 0 --> No Action
if mailboxName is "INBOX" then return 0 --> No Action
--
if mbox is trash mailbox then return 3
if mbox is drafts mailbox then return 0 --> No Action
if mbox is junk mailbox then return 0 --> No Action
if mbox is outbox then return 0 --> No Action
end tell
if (character 1 of mailboxName) is in {"D", "J", "N", "O", "T"} then
if mailboxName starts with "Deleted Messages" then return 0 -- No Action
if mailboxName starts with "Drafts" then return 0 -- No Action
if mailboxName starts with "Junk" then return 0 -- No Action
if mailboxName starts with "Notes" then return 0 -- No Action
if mailboxName starts with "Outbox" then return 0 -- No Action
if mailboxName starts with "ToDos" then return 0 -- No Action
end if
At this point the mailbox (mbox) should be "On My Mac".
The rest of this handler gets the Finder's path to the mailbox's .mbox folder with this ...
and lots of other stuff not applicable here. Perhaps something I've said here is helpful.