• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Mailboxes in Mail & Applescript
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Mailboxes in Mail & Applescript


  • Subject: Re: Mailboxes in Mail & Applescript
  • From: Luther Fuller <email@hidden>
  • Date: Thu, 26 Apr 2012 10:57:13 -0500

On Apr 26, 2012, at 7:35 AM, John Mitchell wrote:

I use this code:

tell application "Mail"
set mailDefaultList to {"In", "Out", "Sent", "Drafts", "Trash", "Junk"}
try
set folderList to {}
-- can I restrict this to top level only?
set folderCount to count of mailboxes --of mailbox "ON MY MAC"
repeat with thisFolder from 1 to folderCount
if mailDefaultList does not contain (name of mailbox thisFolder) then
set end of folderList to (name of mailbox thisFolder)
end if
end repeat
on error errMsg number errNum
-- some error
return {false, ""}
end try
end tell

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 ?)

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users

This email sent to email@hidden

References: 
 >Mailboxes in Mail & Applescript (From: John Mitchell <email@hidden>)

  • Prev by Date: Safari auto pause and resume script
  • Next by Date: Re: Am I missing something here? I thought there was an elegant way to do this.
  • Previous by thread: Mailboxes in Mail & Applescript
  • Next by thread: Mailboxes in Mail & Applescript
  • Index(es):
    • Date
    • Thread