thanks for that suggestion; I used it to work out a satisfactory solution as follows:
if emailApp is "Mail" then
tell application "Mail"
set mailReserveList to {"Deleted Messages", "In", "Outbox", "Sent", "Out", "info", "Drafts", "Trash", "Junk"}
set folderList to {}
set flag to false
try
--select the first mailbox
set mboxCont to mailbox 1
-- find its container
set mbxContainer to container of mboxCont
-- find its container (should be "on My Mac")
set ommCount to (count of mailboxes in container of mbxContainer)
if ommCount > 0 then
-- count is of the mailboxes at the top level
set flag to true
set folderList to (name of every mailbox in container of mbxContainer)
-- remove reserved mailboxes
repeat with itemToRemove in mailReserveList
set ad to itemToRemove as string
set listCount to (length of folderList)
repeat with i from 1 to listCount
set listItem to item i of folderList
--display dialog itemToRemove & " " & listItem
if listItem = ad then
set folderList to removeItemFromList(folderList, i) of me
exit repeat
end if
end repeat
end repeat
end if
return {flag, folderList}
on error errMsg number errNum
-- some error
return {false, ""}
end try
end tell
else
-- only works for Apple Mail
return {false, ""}
end if
This correctly finds all the high level mail folders in On My Mac.
And you asked what Os: Lion 10.7.3
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 ...
tell application "Mail"
set mboxCont to mbox
repeat
try
set mboxCont to (container of mboxCont) -- error here when container does not exist
...
...
...
on error
exit repeat
end try
end repeat
end tell
and lots of other stuff not applicable here. Perhaps something I've said here is helpful.
(BTW, is this in Lion or (Snow) Leopard ?)