Re: On My Mac
Re: On My Mac
- Subject: Re: On My Mac
- From: Axel Luttgens <email@hidden>
- Date: Wed, 3 Jun 2009 15:18:41 +0200
Le 1 juin 09 à 20:55, Luther Fuller a écrit :
I've been working on my On_My_Mac handler (below) yesterday
afternoon and all this morning. I haven't been able to improve on
the old original, but I did make some minor changes. I did discover,
using
set mboxName to (name of selMailbox)
that:
The Inbox is named "Inbox" and its sub-mailboxes are named "INBOX";
The Sent mailbox is names "Sent" and its sub-mailboxes begin with
"Sent Messages";
The Trash mailbox is named "Trash" and its sub-mailboxes begin with
"Deleted Messages";
The Junk mailbox is named "Junk" and its sub-mailboxes begin with
"Junk";
The Drafts mailbox is named "Drafts" and its sub-mailboxes begin
with "Drafts".
Mailboxes "On My Mac" have no account.
(But I have encountered error messages that seem to refer to an "On
My Mac" account.)
And now my question: Isn't there a simple way to determine if a
mailbox is "On My Mac"?
(I've been looking for a long time, but have found nothing.)
on On_My_Mac(mbox) -- mbox is a Mail mailbox.
tell application "Mail"
try
set mboxName to (name of mbox) as text
on error
return false -- RSS
end try
if mbox is trash mailbox then return false
if mbox is inbox then return false
if mbox is sent mailbox then return false
if mbox is drafts mailbox then return false
if mbox is junk mailbox then return false
if mbox is outbox then return false
end tell
--
repeat
tell application "Mail"
try
set acnt to (account of mbox)
name of acnt
account type of acnt
return false -- mailboxes On My Mac have no account
end try
end tell
--
if first character of mboxName is in {"I", "D", "J", "N", "O",
"S", "T"} then
if mboxName is "INBOX" then return false
if mboxName starts with "Deleted Messages" then return false
if mboxName starts with "Drafts" then return false
if mboxName starts with "Junk" then return false
if mboxName starts with "Notes" then return false
if mboxName starts with "Outbox" then return false
if mboxName starts with "Sent Messages" then return false
if mboxName starts with "ToDos" then return false
end if
--
try
tell application "Mail"
set outerBox to mbox
set mbox to (container of mbox) -- error here if no outer mailbox
set mboxName to (name of mbox) as text
end tell
on error
exit repeat
end try
end repeat
--
return true
end On_My_Mac
Hello Luther,
Strictly speaking, an "On My Mac" mailbox is a mailbox that is not
related to a mail account.
So, a test like this one might prove sufficient:
if account of (get properties of mbox) is missing value then...
Since Mail.app seems to make all those mailboxes available through its
"mailboxes" element, a heavier yet equivalent test should be:
if {mbox} is in mailboxes then...
Now, it seems that you are more specifically interested in the
mailboxes appearing under the "On My Mac" heading in the left pane of
a message viewer.
Things then tend to be a bit more complicated, as the behavior of a
message viewer is somewhat idiosyncratic, probably so as to provide
the user with a seemingly more consistent view.
For example, as you already noticed, mailbox "Deleted Messages"
contains all messages deleted from local mailboxes but will be
displayed under the "Trash" heading.
Note that, unless I'm wrong, that local mailbox may sometimes be
created with a name other than "Deleted Messages"; as a result, it
would be better to devise a test that doesn't depend on a constant
mailbox name, for example:
if {mbox} is in mailboxes and {mbox} is not in mailboxes of trash
mailbox then...
Then come all those esoteric notes, todos, intelligent mailboxes...
which may or may not visually appear, depending on their current
contents (empty or not) or on some application settings.
For example, one may create a top-level local mailbox named "Junk",
and it will appear under "On My Mac"; but then configure Mail.app to
move junk messages (instead of just signaling such messages), and that
mailbox will now appear somewhere else...
On the other hand, create a top-level local mailbox named "Sent
Messages"; it will unconditionally appear under the "Sent Messages"
heading, with the name "On My Mac"...
More generally, some GUI parts of a message viewer are more or less
well defined in the scripting model, other just seem to be missing; I
fear there is no general answer to your question.
So, here follows an attempt; perhaps may you find it useful as
complementary to what you've already done:
on On_My_Mac(mbox)
local specialNames
-- Is mbox related to an account?
tell application "Mail" to if account of (get properties of mbox) is
not missing value then return false
-- Fetch special names currently defined for local mailboxes...
tell application "System Events"
tell first item of (property list items of property list item
"MailAccounts" of property list file "~/Library/Preferences/
com.apple.mail.plist" whose value of its property list item
"AccountType" is "LocalAccount")
set specialNames to {value of property list item
"DraftsMailboxName", value of property list item "JunkMailboxName",
value of property list item "NotesMailboxName", value of property list
item "SentMessagesMailboxName", value of property list item
"TrashMailboxName"}
end tell
end tell
-- ... as well as other such names that seem to be invariable.
set specialNames to specialNames & {"ToDos", "Outbox"}
-- The above probably needs to be modulated according to current
application settings.
-- Is mbox liable to be displayed somewhere else than "On My Mac"?
tell application "Mail" to if name of mbox is in specialNames then
return false
-- Perhaps some other tests?
-- OK, should be a mail box displayed under "On My Mac"
return true
end On_My_Mac
HTH,
Axel _______________________________________________
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: | |
| >On My Mac (From: Luther Fuller <email@hidden>) |